Re: memory by pid Adolfo wrote:
> Hi!
>
>
> with top I have the following output for vfxsd, size and res
>
>
> Memory: 92468K (54628K) real, 150644K (99824K) virtual, 419316K free
> Page# 1/11
>
> CPU TTY PID USERNAME PRI NI SIZE RES STATE TIME %WCPU %CPU
> COMMAND
> 0 ?
> 48 root 152 20 832K 832K run 0:02 0.38 0.38
> vxfsd
>
>
> But what does it mean, with UNIX95
>
> root:/ #UNIX95= ps -ef -o pid,sz,vsz,comm|grep vxfsd
> PID SZ VSZ COMMAND
> 48 0 0 vxfsd
>
That is odd... looks like ps skips reporting sizes for kernel daemons in
UNIX95 mode.
Poking around a bit on a box -- I think ps is closer to right (there's
a UAREA there (local kernel stack), but nothing else... but top reports:
6 ? 1069547576 root 191 20 1312K 1312K run 0:04 1.20
1.20 vxf
vs.
# ./object_dump -v 1069547576
VIRT/PHYS/LOCKED/SWAP summaries in pages.
System page size is 4096 or 0x1000 bytes.
Object 1: UAREA at VA 0x400003ffffff0000 to VA 0x400003ffffff7fff.
VIRT: 8 PHYS: 0 LOCKED: 0 SWAP: 0
PID 1069547519:
UNUSED TYPE consumes 0 VIRT, 0 PHYS, 0 LOCKED and 0 SWAP.
UAREA consumes 8 VIRT, 0 PHYS, 0 LOCKED and 0 SWAP.
TEXT consumes 0 VIRT, 0 PHYS, 0 LOCKED and 0 SWAP.
DATA/HEAP consumes 0 VIRT, 0 PHYS, 0 LOCKED and 0 SWAP.
MAIN STACK consumes 0 VIRT, 0 PHYS, 0 LOCKED and 0 SWAP.
SYSV SHMEM consumes 0 VIRT, 0 PHYS, 0 LOCKED and 0 SWAP.
NULL DEREF consumes 0 VIRT, 0 PHYS, 0 LOCKED and 0 SWAP.
MEM MAPPED I/O consumes 0 VIRT, 0 PHYS, 0 LOCKED and 0 SWAP.
MMAP consumes 0 VIRT, 0 PHYS, 0 LOCKED and 0 SWAP.
GRAPHICS SPECIFIC consumes 0 VIRT, 0 PHYS, 0 LOCKED and 0 SWAP.
GRAPHICS SPECIFIC consumes 0 VIRT, 0 PHYS, 0 LOCKED and 0 SWAP.
RSE STACK consumes 0 VIRT, 0 PHYS, 0 LOCKED and 0 SWAP.
So I have no idea where top is adding in the extra object.. but top is
known to be approximate anyway.
> Where is pstat?
>
> root:/ #find / -name pstat
> /usr/include/sys/pstat
> /var/adm/sw/save/PHKL_31500/C-INC/usr/include/sys/pstat
> root:/ #/usr/include/sys/pstat
> ksh: /usr/include/sys/pstat: cannot execute
man pstat -- pstat is the general name for a set of system calls
that provide a lot of information on the system. pstat_getproc()
and pstat_getprocvm() are what you'd need in this case. Sample
code attached, no promises made as to reliability of such (or
elegance for that matter...). Compile it 64-bit (or make sure
to use -D_PSTAT64).
Don
>
> Regards
> Don Morris escribió:
>> Adolfo wrote:
>>
>>> Hello,
>>>
>>>
>>> Is there any command to see the memory, physical and swap, that it is
>>> using any process?
>>>
>>> Regards
>>
>>
>> UNIX95=1 ps -ef -o pid,sz,vsz,comm
>>
>> should get you started. If you need something more detailed (usage by
>> object type) you'll need to use pstat or Glance.
>>
>> Don
#include <stdio.h>
#include <unistd.h>
#include <sys/mman.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/param.h>
#include <sys/pstat.h>
#ifdef PS_RSESTACK /* 11.22 and later */
#define LAST_VM_TYPE PS_RSESTACK
#else /* prior non-IPF */
#define LAST_VM_TYPE PS_GRAPHICS_DMA
#endif /* PS_RSESTACK */
uint32_t virt_totals[LAST_VM_TYPE+1];
uint32_t phys_totals[LAST_VM_TYPE+1];
uint32_t swap_totals[LAST_VM_TYPE+1];
uint32_t mlock_totals[LAST_VM_TYPE+1];
void
print_type(int type) {
switch(type) {
case PS_USER_AREA:
printf(" UAREA ");
return;
case PS_TEXT:
printf(" TEXT ");
return;
case PS_DATA:
printf(" DATA/HEAP ");
return;
case PS_STACK:
printf(" MAIN STACK ");
return;
#ifdef PS_RSESTACK
case PS_RSESTACK:
printf(" RSE STACK ");
return;
#endif /* PS_RSESTACK */
case PS_IO:
printf(" MEM MAPPED I/O ");
return;
case PS_SHARED_MEMORY:
printf(" SYSV SHMEM ");
return;
case PS_NULLDEREF:
printf(" NULL DEREF ");
return;
case PS_MMF:
printf(" MMAP ");
return;
case PS_GRAPHICS:
case PS_GRAPHICS_DMA:
printf(" GRAPHICS SPECIFIC ");
return;
default:
printf(" UNUSED TYPE ");
}
return;
}
int
main(int argc, char *argv[])
{
int error;
struct pst_vm_status pvs;
struct pst_status ps;
int i, j, k, verbose, get_all;
pid_t target;
int valid = 0;
size_t sys_page_size;
int done = 0;
size_t count;
_T_LONG_T last_pid = -1;
verbose = 0;
target = 0;
get_all = 0;
if ( argc > 3 ) {
printf("USAGE: %s <-v> <target_pid>\n", argv[0]);
}
if ( argc == 2 ) {
target = atoi(argv[1]);
} else if ( argc == 3 ){
verbose = 1;
target = atoi(argv[2]);
} else {
get_all = 1;
}
sys_page_size = sysconf(_SC_PAGE_SIZE);
j = 0;
printf("VIRT/PHYS/LOCKED/SWAP summaries in pages.\n");
printf("System page size is %ld or 0x%lx bytes.\n",
sys_page_size, sys_page_size);
do {
if ( get_all ) {
target = j++;
count = (size_t)1;
} else {
count = 0;
}
done = (pstat_getproc(&ps, sizeof(struct pst_status),
(size_t)1, j++) <= 0 );
if ( done ) {
break;
}
if ( ps.pst_pid == last_pid ) {
continue;
}
last_pid = ps.pst_pid;
for ( k = 0; k <= LAST_VM_TYPE; k++ ) {
virt_totals[k] = 0;
phys_totals[k] = 0;
swap_totals[k] = 0;
mlock_totals[k] = 0;
}
i = 0;
while(pstat_getprocvm(&pvs, sizeof(struct pst_vm_status),
(size_t)ps.pst_pid, i++) > 0 ) {
valid = 1;
if ( verbose ) {
printf("Object %d: ", i);
print_type(pvs.pst_type);
printf(" at VA 0x%lx to VA 0x%lx.\n\t",
pvs.pst_vaddr,
pvs.pst_vaddr +
(pvs.pst_length * sys_page_size) - 1);
printf( "\tVIRT: %ld \tPHYS: %ld \tLOCKED:"
" %ld\tSWAP: %ld \n",
pvs.pst_length, pvs.pst_phys_pages,
pvs.pst_lockmem, pvs.pst_swap);
}
virt_totals[pvs.pst_type] += pvs.pst_length;
phys_totals[pvs.pst_type] += pvs.pst_phys_pages;
swap_totals[pvs.pst_type] += pvs.pst_swap;
mlock_totals[pvs.pst_type] += pvs.pst_lockmem;
}
if ( valid ) {
printf("PID %ld:\n",ps.pst_pid);
}
for ( k = 0; k <= LAST_VM_TYPE && valid; k++ ) {
print_type(k);
printf( " consumes %ld VIRT, %ld PHYS, %ld LOCKED"
" and %ld SWAP.\n",
virt_totals[k], phys_totals[k], mlock_totals[k],
swap_totals[k]);
virt_totals[k] = 0;
phys_totals[k] = 0;
mlock_totals[k] = 0;
swap_totals[k] = 0;
}
valid = 0;
} while (get_all);
exit(0);
} |