Skip to contentSkip to conversation

introduce TASK_SIZE_OF() for all arches

RFC PATCH In review Dave Hansen 5 participants 9 messages Aug 21, 2007 – Aug 23, 2007

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 introduce TASK_SIZE_OF() for all arches

For the /proc/<pid>/pagemap code[1], we need to able to query how much virtual address space a particular task has. The trick is that we do it through /proc and can't use TASK_SIZE since it references "current" on some arches. The process opening the /proc file might be a 32-bit process opening a 64-bit process's pagemap file.

x86_64 already has a TASK_SIZE_OF() macro:

#define TASK_SIZE_OF(child) ((test_tsk_thread_flag(child, TIF_IA32)) ? IA32_PAGE_OFFSET : TASK_SIZE64)

I'd like to have that for other architectures. So, add it for all the architectures that actually use "current" in their TASK_SIZE. For the others, just add a quick #define in sched.h to use plain old TASK_SIZE.

1. http://www.linuxworld.com/news/2007/042407-kernel.html

---

 lxc-dave/include/asm-ia64/processor.h    |    3 ++-
 lxc-dave/include/asm-parisc/processor.h  |    3 ++-
 lxc-dave/include/asm-powerpc/processor.h |    4 +++-
 lxc-dave/include/asm-s390/processor.h    |    2 ++
 lxc-dave/include/linux/sched.h           |    4 ++++
 5 files changed, 13 insertions(+), 3 deletions(-)
include/asm-ia64/processor.h renamed from include/asm-ia64/processor.h~task_size_of +2 -1
diff -puN include/asm-ia64/processor.h~task_size_of include/asm-ia64/processor.h
@@ -31,7 +31,8 @@
  * each (assuming 8KB page size), for a total of 8TB of user virtual
  * address space.
  */
-#define TASK_SIZE		(current->thread.task_size)
+#define TASK_SIZE_OF(tsk)	((tsk)->thread.task_size)
+#define TASK_SIZE       	TASK_SIZE_OF(current)
 
 /*
  * This decides where the kernel will search for a free chunk of vm
include/asm-parisc/processor.h renamed from include/asm-parisc/processor.h~task_size_of +2 -1
diff -puN include/asm-parisc/processor.h~task_size_of include/asm-parisc/processor.h
@@ -32,7 +32,8 @@
 #endif
 #define current_text_addr() ({ void *pc; current_ia(pc); pc; })
 
-#define TASK_SIZE               (current->thread.task_size)
+#define TASK_SIZE_OF(tsk)       ((tsk)->thread.task_size)
+#define TASK_SIZE	         (current->thread.task_size)
 #define TASK_UNMAPPED_BASE      (current->thread.map_base)
 
 #define DEFAULT_TASK_SIZE32	(0xFFF00000UL)
include/asm-powerpc/processor.h renamed from include/asm-powerpc/processor.h~task_size_of +3 -1
diff -puN include/asm-powerpc/processor.h~task_size_of include/asm-powerpc/processor.h
@@ -107,7 +107,9 @@ extern struct task_struct *last_task_use
  */
 #define TASK_SIZE_USER32 (0x0000000100000000UL - (1*PAGE_SIZE))
 
-#define TASK_SIZE (test_thread_flag(TIF_32BIT) ? \
+#define TASK_SIZE	  (test_thread_flag(TIF_32BIT) ? \
+		TASK_SIZE_USER32 : TASK_SIZE_USER64)
+#define TASK_SIZE_OF(tsk) (test_tsk_thread_flag(tsk, TIF_32BIT) ? \
 		TASK_SIZE_USER32 : TASK_SIZE_USER64)
 
 /* This decides where the kernel will search for a free chunk of vm
include/asm-s390/processor.h renamed from include/asm-s390/processor.h~task_size_of +2 -0
diff -puN include/asm-s390/processor.h~task_size_of include/asm-s390/processor.h
@@ -75,6 +75,8 @@ extern struct task_struct *last_task_use
 
 # define TASK_SIZE		(test_thread_flag(TIF_31BIT) ? \
 					(0x80000000UL) : (0x40000000000UL))
+# define TASK_SIZE_OF(tsk)	(test_tsk_thread_flag(tsk, TIF_31BIT) ? \
+					(0x80000000UL) : (0x40000000000UL))
 # define TASK_UNMAPPED_BASE	(TASK_SIZE / 2)
 # define DEFAULT_TASK_SIZE	(0x40000000000UL)
 
include/linux/sched.h renamed from include/linux/sched.h~task_size_of +4 -0
diff -puN include/linux/sched.h~task_size_of include/linux/sched.h
@@ -1712,6 +1712,10 @@ static inline void inc_syscw(struct task
 }
 #endif
 
+#ifndef TASK_SIZE_OF
+#define TASK_SIZE_OF(tsk)	TASK_SIZE
+#endif
+
 #endif /* __KERNEL__ */
 
 #endif

_

#1 lore raw
Quoted 4 lines · Dave Hansen

I'd like to have that for other architectures. So, add it for all the architectures that actually use "current" in their TASK_SIZE. For the others, just add a quick #define in sched.h to use plain old TASK_SIZE.

MIPS seems to do things a little differently ... Ralf, what should Dave be doing here?

#define TASK_SIZE32 0x7fff8000UL
#define TASK_SIZE 0x10000000000UL

Signature · 3 lines
"Bill, look, we understand that you're interested in selling us this
operating system, but compare it to ours.  We can't possibly take such
a retrograde step."
#2 lore raw
Quoted 11 lines · Matthew Wilcox
Quoted 4 lines · Dave Hansen

I'd like to have that for other architectures. So, add it for all the architectures that actually use "current" in their TASK_SIZE. For the others, just add a quick #define in sched.h to use plain old TASK_SIZE.

MIPS seems to do things a little differently ... Ralf, what should Dave be doing here?

#define TASK_SIZE32 0x7fff8000UL
#define TASK_SIZE 0x10000000000UL

Indeed. Below patch should do the trick.

Ralf

include/asm-mips/processor.h +4 -0
index 83bc945..0e79e03 100644
@@ -45,6 +45,8 @@ extern unsigned int vced_count, vcei_count;
  * space during mmap's.
  */
 #define TASK_UNMAPPED_BASE	(PAGE_ALIGN(TASK_SIZE / 3))
+#define TASK_SIZE_OF(tsk)						\
+	(test_thread_flag(TIF_32BIT_ADDR) ? TASK_SIZE32 : TASK_SIZE)
 #endif
 
 #ifdef CONFIG_64BIT
@@ -65,6 +67,8 @@ extern unsigned int vced_count, vcei_count;
 #define TASK_UNMAPPED_BASE						\
 	(test_thread_flag(TIF_32BIT_ADDR) ?				\
 		PAGE_ALIGN(TASK_SIZE32 / 3) : PAGE_ALIGN(TASK_SIZE / 3))
+#define TASK_SIZE_OF(tsk)						\
+	(test_thread_flag(TIF_32BIT_ADDR) ? TASK_SIZE32 : TASK_SIZE)
 #endif
 
 #define NUM_FPU_REGS	32
#3 lore raw
Quoted 8 lines · Ralf Baechle
Quoted 6 lines · Matthew Wilcox
Quoted 4 lines · Dave Hansen

I'd like to have that for other architectures. So, add it for all the architectures that actually use "current" in their TASK_SIZE. For the others, just add a quick #define in sched.h to use plain old TASK_SIZE.

Quoted 7 lines
Quoted 5 lines

MIPS seems to do things a little differently ... Ralf, what should Dave be doing here?

#define TASK_SIZE32 0x7fff8000UL
#define TASK_SIZE 0x10000000000UL

Indeed. Below patch should do the trick.

Thanks for the patch. I'll roll it into my larger one.

-- Dave

#4 lore raw
In reply to Dave Hansen
Quoted 2 lines · Dave Hansen

For the /proc/<pid>/pagemap code[1], we need to able to query how much virtual address space a particular task has.

How does this relate to NOMMU conditions?

David

#5 lore raw
Quoted 6 lines · David Howells
Quoted 2 lines · Dave Hansen

For the /proc/<pid>/pagemap code[1], we need to able to query how much virtual address space a particular task has.

How does this relate to NOMMU conditions?

It probably doesn't make any sense to use the /proc/<pid>/pagemap feature on NOMMU systems. There are no pagetables to dump, and no shared pages, right?

-- Dave

#6 lore raw
Quoted 11 lines · Dave Hansen
Quoted 6 lines · David Howells
Quoted 2 lines · Dave Hansen

For the /proc/<pid>/pagemap code[1], we need to able to query how much virtual address space a particular task has.

How does this relate to NOMMU conditions?

It probably doesn't make any sense to use the /proc/<pid>/pagemap feature on NOMMU systems. There are no pagetables to dump, and no shared pages, right?

Nor is there any present/not present to report. VSS == RSS on NOMMU, right?

So we could provide pagemap, but it's not clear it'd be very interesting. kpagemap might be interesting, simply because of the flags though.

Signature · 1 line
Mathematics is the supreme nostalgia of our time.
#7 lore raw
In reply to David Howells
Quoted 5 lines · David Howells
Quoted 2 lines · Dave Hansen

For the /proc/<pid>/pagemap code[1], we need to able to query how much virtual address space a particular task has.

How does this relate to NOMMU conditions?

Were you asking about /proc/<pid>/pagemap, or about my TASK_SIZE_OF() macro?

/proc/<pid>/pagemap is completely implemented in task_mmu.c, so it shouldn't show up on NOMMU systems.

As far as TASK_SIZE_OF(), it still makes sense on those systems because they (at least m68k) still has TASK_SIZE. Was there a particular problem you're concerned about? I'm not very intimately familiar with the NOMMU code.

-- Dave

#8 lore raw
Quoted 2 lines · Dave Hansen

Were you asking about /proc/<pid>/pagemap, or about my TASK_SIZE_OF() macro?

TASK_SIZE_OF().

Quoted 2 lines

As far as TASK_SIZE_OF(), it still makes sense on those systems because they (at least m68k) still has TASK_SIZE.

Fair enough.

Quoted 2 lines

Was there a particular problem you're concerned about? I'm not very intimately familiar with the NOMMU code.

Since you were talking about virtual memory, I was wondering as to its applicability for NOMMU.

David