LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Thread Tools
Old 02-23-2004, 11:29 PM   #1
eshwar_ind
Member
 
Registered: Feb 2004
Location: Bangalore
Distribution: Redhat
Posts: 144
Thanked: 0
get Page size


[Log in to get rid of this advertisement]
Hi!
How can we get the page size in linux. Can i change that in in aprogram?
In Kernel module programming is there any way to get the memory pieces just like 10 bytes, 2 bytes? ( i think kmalloc allocates entire page if the requested memory is less than the page size So its a waste of remaining memory)
Please reply me.
bye,
Eshwar.
eshwar_ind is offline     Reply With Quote
Old 02-24-2004, 04:01 AM   #2
jinksys
Member
 
Registered: Aug 2003
Location: 63123
Distribution: OpenSuSE/Ubuntu
Posts: 417
Thanked: 0
To get page size:

Code:
#include <stdio.h>
#include <unistd.h>

int main()
{
printf("%i,	getpagesize());
return 0;
}
Simply put, you cant change the page size. And due to the way the kernel allocates memory and fragmentation within the system's physical memory, memory allocation with kmalloc isn't precise as with malloc. You'll often get a pointer to a larger chunk of memory than requested, sometimes up to double the amount.

Last edited by jinksys; 02-24-2004 at 04:04 AM..
jinksys is offline     Reply With Quote
Old 02-24-2004, 02:45 PM   #3
infamous41md
Member
 
Registered: Mar 2003
Posts: 804
Thanked: 0
to add one thing to the above, kmalloc keeps around a pool of various sized memory objects. whether or not there is one as small as 10 bytes, i doubt, but you should recieve the next largest chunk if that pool has a free chunk. if you are going to be allocating a large quantity of constant size memory chunks, you may want to look into having kmalloc create a special pool of objects for you of that size using kmem_cache_create() and kmem_cache_alloc() from [kernel/slab/mm.c].
infamous41md is offline     Reply With Quote
Old 02-24-2004, 08:17 PM   #4
jinksys
Member
 
Registered: Aug 2003
Location: 63123
Distribution: OpenSuSE/Ubuntu
Posts: 417
Thanked: 0
I seriously doubt youll get a buffer of 10bytes using kmalloc, since the minimum memory that kmalloc handles is anywhere from 32 to 64 bytes, depending on page size and kernel.
jinksys is offline     Reply With Quote
Old 02-25-2004, 12:49 AM   #5
eshwar_ind
Member
 
Registered: Feb 2004
Location: Bangalore
Distribution: Redhat
Posts: 144
Thanked: 0

Original Poster
Quote:
Originally posted by jinksys
I seriously doubt youll get a buffer of 10bytes using kmalloc, since the minimum memory that kmalloc handles is anywhere from 32 to 64 bytes, depending on page size and kernel.
eshwar_ind is offline     Reply With Quote
Old 02-25-2004, 12:50 AM   #6
eshwar_ind
Member
 
Registered: Feb 2004
Location: Bangalore
Distribution: Redhat
Posts: 144
Thanked: 0

Original Poster
Hi guys thank you very much.
eshwar_ind is offline     Reply With Quote

Reply

Bookmarks


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
OpenOffice.org 2.0RC - Default Page Size A4 ? Yalla-One Linux - Software 6 10-28-2005 12:00 PM
adjusting the size of a web page mrobertson Programming 1 08-10-2005 09:50 AM
Next page link size azucaro LQ Suggestions & Feedback 1 06-13-2005 07:51 PM
Page size in printing jontyrhodes Linux - General 2 05-21-2004 09:20 PM
Cups/Printer Page size matt3333 Linux - Software 26 03-16-2004 11:41 PM


All times are GMT -5. The time now is 02:41 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration