Skip to contentSkip to conversation

>3k call path in ncpfs

STACK New Jörn Engel 3 participants 5 messages Jun 9, 2004 – Jun 10, 2004

lore
Share & tools
lore
#0 lore raw

ncpfs has a few stack-hungry functions. Could you try to put ncp_ioctl() and/or ncp_conn_logged_in() on a diet? Example call path is below.

stackframes for call path too long (3004):

    size  function
     720  ncp_ioctl
     616  ncp_conn_logged_in
      24  ncp_lookup_volume
       0  ncp_request2
     164  sock_sendmsg
       0  wait_on_sync_kiocb
      84  schedule
      16  __put_task_struct
      20  audit_free
      36  audit_log_start
      16  __kmalloc
       0  __get_free_pages
      28  __alloc_pages
     284  try_to_free_pages
       0  out_of_memory
       0  mmput
      16  exit_aio
       0  __put_ioctx
      16  do_munmap
       0  split_vma
      36  vma_adjust
       0  fput
       0  __fput
       0  locks_remove_flock
      12  panic
       0  sys_sync
       0  sync_inodes
     308  sync_inodes_sb
       0  do_writepages
     128  mpage_writepages
       4  write_boundary_block
       0  ll_rw_block
      28  submit_bh
       0  bio_alloc
      88  mempool_alloc
     256  wakeup_bdflush
      20  pdflush_operation
       0  printk
       0  preempt_schedule
      84  schedule

Jörn

Signature · 2 lines
Time? What's that? Time is only worth what you do with it.
-- Theo de Raadt
#1 lore raw

Jörn, do you have any analysis of stack usage for x86-64 or other 64-bit processors? I assume they would more readily reach the 4K stack boundaries as all longs and pointers are 8 bytes instead of 4.

Thanks,
-Byron

--

Byron Stanoszek                         Ph: (330) 644-3059
Systems Programmer                      Fax: (330) 644-8110
Commercial Timesharing Inc.             Email: [email protected]
#2 lore raw
Quoted 4 lines · Byron Stanoszek

Jörn, do you have any analysis of stack usage for x86-64 or other 64-bit processors? I assume they would more readily reach the 4K stack boundaries as all longs and pointers are 8 bytes instead of 4.

No I don't, the tool isn't even tested on anything but i386. Do any 64bit architectures use 4k stacks?

Jörn

Signature · 3 lines
If you're willing to restrict the flexibility of your approach,
you can almost always do something better.
-- John Carmack
#3 lore raw
Quoted 8 lines · Jörn Engel
Quoted 4 lines · Byron Stanoszek

Jörn, do you have any analysis of stack usage for x86-64 or other 64-bit processors? I assume they would more readily reach the 4K stack boundaries as all longs and pointers are 8 bytes instead of 4.

No I don't, the tool isn't even tested on anything but i386. Do any 64bit architectures use 4k stacks?

Guess not :) I thought I saw it as an option on my x86-64 here but I guess I was compiling too many different kernels this week.

Sorry for the mixup!

-Byron

--

Byron Stanoszek                         Ph: (330) 644-3059
Systems Programmer                      Fax: (330) 644-8110
Commercial Timesharing Inc.             Email: [email protected]
#4 lore raw

PATCH 1/1 Decrease stack usage in ncpfs's ioctl (was Re: [STACK] >3k call path in ncpfs)

In reply to Jörn Engel
Quoted 8 lines · Jörn Engel

ncpfs has a few stack-hungry functions. Could you try to put ncp_ioctl() and/or ncp_conn_logged_in() on a diet? Example call path is below.

stackframes for call path too long (3004):

    size  function
     720  ncp_ioctl
     616  ncp_conn_logged_in

Hi Andrew,
please apply this. It decreases stack consumption in one of
ncpfs's paths from 3000 to 2200 bytes (and stack portion in ncpfs ioctl code from 1336 to 452 bytes).
Thanks,
Petr Vandrovec

Decrease stack usage in ncpfs's ncp_ioctl:
* some code used large structure (with embeded 256 bytes for filename) while it never passed filename around. Use something smaller in ncp_conn_logged_in. Decrease 616 => 300.
* gcc-3.3 is very bad when it comes to parallel blocks in ioctl. Split some branches from large switch to separate functions. ncp_ioctl now uses 152 bytes of stack (instead of 720) and biggest child 64.

fs/ncpfs/dir.c +5 -5
diff -urdN linux/fs/ncpfs/dir.c linux/fs/ncpfs/dir.c
@@ -762,12 +762,12 @@
 int ncp_conn_logged_in(struct super_block *sb)
 {
 	struct ncp_server* server = NCP_SBP(sb);
-	struct nw_info_struct i;
 	int result;
 
 	if (ncp_single_volume(server)) {
 		int len;
 		struct dentry* dent;
+		__u32 volNumber, dirEntNum, DosDirNum;
 		__u8 __name[NCP_MAXPATHLEN + 1];
 
 		len = sizeof(__name);
@@ -776,7 +776,7 @@
 		if (result)
 			goto out;
 		result = -ENOENT;
-		if (ncp_lookup_volume(server, __name, &i)) {
+		if (ncp_get_volume_root(server, __name, &volNumber, &dirEntNum, &DosDirNum)) {
 			PPRINTK("ncp_conn_logged_in: %s not found\n",
 				server->m.mounted_vol);
 			goto out;
@@ -785,9 +785,9 @@
 		if (dent) {
 			struct inode* ino = dent->d_inode;
 			if (ino) {
-				NCP_FINFO(ino)->volNumber = i.volNumber;
-				NCP_FINFO(ino)->dirEntNum = i.dirEntNum;
-				NCP_FINFO(ino)->DosDirNum = i.DosDirNum;
+				NCP_FINFO(ino)->volNumber = volNumber;
+				NCP_FINFO(ino)->dirEntNum = dirEntNum;
+				NCP_FINFO(ino)->DosDirNum = DosDirNum;
 			} else {
 				DPRINTK("ncpfs: sb->s_root->d_inode == NULL!\n");
 			}
fs/ncpfs/ioctl.c +160 -157

353 lines not on this page · raw message

fs/ncpfs/ncplib_kernel.c +29 -17

82 lines not on this page · raw message

fs/ncpfs/ncplib_kernel.h +5 -3
diff -urdN linux/fs/ncpfs/ncplib_kernel.h linux/fs/ncpfs/ncplib_kernel.h
@@ -70,7 +70,9 @@
 int ncp_obtain_info(struct ncp_server *server, struct inode *, char *,
 		struct nw_info_struct *target);
 int ncp_obtain_nfs_info(struct ncp_server *server, struct nw_info_struct *target);
-int ncp_lookup_volume(struct ncp_server *, char *, struct nw_info_struct *);
+int ncp_get_volume_root(struct ncp_server *server, const char *volname, 
+			__u32 *volume, __u32 *dirent, __u32 *dosdirent);
+int ncp_lookup_volume(struct ncp_server *, const char *, struct nw_info_struct *);
 int ncp_modify_file_or_subdir_dos_info(struct ncp_server *, struct inode *,
 	 __u32, const struct nw_modify_dos_info *info);
 int ncp_modify_file_or_subdir_dos_info_path(struct ncp_server *, struct inode *,
@@ -111,8 +113,8 @@
 #endif	/* CONFIG_NCPFS_IOCTL_LOCKING */
 
 int
-ncp_mount_subdir(struct ncp_server *, struct nw_info_struct *,
-			__u8, __u8, __u32);
+ncp_mount_subdir(struct ncp_server *, __u8, __u8, __u32,
+		 __u32* volume, __u32* dirent, __u32* dosdirent);
 int ncp_dirhandle_alloc(struct ncp_server *, __u8 vol, __u32 dirent, __u8 *dirhandle);
 int ncp_dirhandle_free(struct ncp_server *, __u8 dirhandle);