Max number of processes? Advice, please.

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
Post Reply
User avatar
gravaera
Member
Member
Posts: 737
Joined: Tue Jun 02, 2009 4:35 pm
Location: Supporting the cause: Use \tabs to indent code. NOT \x20 spaces.

Max number of processes? Advice, please.

Post by gravaera »

I've been working on my Mem Mgr, and I have two implemented in my kernel. A rudimentary, crude one that, at startup, makes the assumption that there is 1MB memory in all, and uses a bitmap to handle pages. This crude mem mgr only keeps track of pages in lower mem.

It automatically maps the first page in lower mem as being used, and then goes on to map all mem pages above 512KB up to 1MB as being used as well.

Its purpose is to ensure there is a competent (enough) allocator for resources during the initial stage of setting up the kernel process. The very first thing my kernel does is set up its own process. I have use an array[8096] of type proc_data_t (which is 48B per entry) to keep tabs on processes.

This implies that my kernel will have a maximum number of 8092 processes. And the array is given pages in Low Mem, as I indicated above.

As soon as the kernel process's data is filled out in the second index of the array (index 0 is a null process, and index 1 is the kernel), the REAL McCoy Mem Mgr is brought out, and implements paging, and whatnot.

The math for the Low Mem indicates that below 512KB there are approx 128 pages. And allocating 8092*48B = 95 pages. Please note that I KNOW I'm overwriting the Bootloader @ 0x7C00.

This max number of processes has been bothering me, so I wonder: does it make sense? Have you ever seen any 'puter with more than even 4000 processes? Would a server PC be running more than 8092, by chance?
Attachments
memory_smgr_init.cpp
Declarations. The Mem Smgr_init_t struct mimics a C++ class since I have no mem MGR at boot to do dynamic class initialization. That's pretty much the reason why I needed an initial, crude Mem Mgr to start things off.
(3.42 KiB) Downloaded 144 times
memory_smgr_init.h
Header file...
(1.39 KiB) Downloaded 105 times
Last edited by gravaera on Sun Aug 02, 2009 1:18 pm, edited 1 time in total.
17:56 < sortie> Paging is called paging because you need to draw it on pages in your notebook to succeed at it.
User avatar
NickJohnson
Member
Member
Posts: 1249
Joined: Tue Mar 24, 2009 8:11 pm
Location: Sunnyvale, California

Re: Max number of processes? Advice, please.

Post by NickJohnson »

That should be plenty of processes - afaik, Linux has a max of 32768 processes, and most of the time on my box there are only ~70 processes (1-2 running). You can also assume at least 4 MB of memory on a machine that can use protected mode. You should also try to dynamically allocate those process structures somehow. I suggest having a 2D array where the sub-arrays are allocated on demand.
User avatar
Creature
Member
Member
Posts: 548
Joined: Sat Dec 27, 2008 2:34 pm
Location: Belgium

Re: Max number of processes? Advice, please.

Post by Creature »

NickJohnson wrote:That should be plenty of processes - afaik, Linux has a max of 32768 processes, and most of the time on my box there are only ~70 processes (1-2 running). You can also assume at least 4 MB of memory on a machine that can use protected mode. You should also try to dynamically allocate those process structures somehow. I suggest having a 2D array where the sub-arrays are allocated on demand.
Yes, a (possibly, but not necessarily, doubly) linked list would be best I think and the least memory-absorbing.
When the chance of succeeding is 99%, there is still a 50% chance of that success happening.
User avatar
gravaera
Member
Member
Posts: 737
Joined: Tue Jun 02, 2009 4:35 pm
Location: Supporting the cause: Use \tabs to indent code. NOT \x20 spaces.

Re: Max number of processes? Advice, please.

Post by gravaera »

That gives me an idea, actually: I could leave the 8092 processes as they are, in low mem, and then, probably, the kernel would keep track of processes, and if more than 8092 processes are needed, I could, from there, have a "higher processes" linked list, which handles all processes above 8092. Maybe...
17:56 < sortie> Paging is called paging because you need to draw it on pages in your notebook to succeed at it.
earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

Re: Max number of processes? Advice, please.

Post by earlz »

holypanl wrote:That gives me an idea, actually: I could leave the 8092 processes as they are, in low mem, and then, probably, the kernel would keep track of processes, and if more than 8092 processes are needed, I could, from there, have a "higher processes" linked list, which handles all processes above 8092. Maybe...
I would say its a waste of memory. a linked list or something of that sort would be much better
User avatar
gravaera
Member
Member
Posts: 737
Joined: Tue Jun 02, 2009 4:35 pm
Location: Supporting the cause: Use \tabs to indent code. NOT \x20 spaces.

Re: Max number of processes? Advice, please.

Post by gravaera »

earlz wrote:
holypanl wrote:That gives me an idea, actually: I could leave the 8092 processes as they are, in low mem, and then, probably, the kernel would keep track of processes, and if more than 8092 processes are needed, I could, from there, have a "higher processes" linked list, which handles all processes above 8092. Maybe...
I would say its a waste of memory. a linked list or something of that sort would be much better
True. But the array is also allocated within lower memory. I'm not entirely sure, but lower memory isn't normally needed when an OS goes into full swing. Does Windows or *Nix use lower memory for anything?
17:56 < sortie> Paging is called paging because you need to draw it on pages in your notebook to succeed at it.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Max number of processes? Advice, please.

Post by Combuster »

holypanl wrote:I'm not entirely sure, but lower memory isn't normally needed when an OS goes into full swing. Does Windows or *Nix use lower memory for anything?
Lower memory is just more memory, which is meant to be used. Do you really think common OSes would forego memory that works the same way as higher memory? It also has another advantage: it can be used for ISA DMA transactions.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
NickJohnson
Member
Member
Posts: 1249
Joined: Tue Mar 24, 2009 8:11 pm
Location: Sunnyvale, California

Re: Max number of processes? Advice, please.

Post by NickJohnson »

Creature wrote: Yes, a (possibly, but not necessarily, doubly) linked list would be best I think and the least memory-absorbing.
But if you want to find a process quickly, a two-level array would be much better. I have an area of virtual memory that works as a linear table of processes, but the pages behind it are allocated on demand, so at most a page of memory is wasted at a time. Using the heap to allocate each process entry individually (to put in the linked list) would probably take more memory and time in the end.
holypanl wrote:Does Windows or *Nix use lower memory for anything?
The chunk of lower memory from 0x500 to 0x80000 (or up to 0xF8000) can be used just like any other memory, so it's usually added to the pile of frames like extended memory. Half a megabyte can always be useful.
User avatar
gravaera
Member
Member
Posts: 737
Joined: Tue Jun 02, 2009 4:35 pm
Location: Supporting the cause: Use \tabs to indent code. NOT \x20 spaces.

Re: Max number of processes? Advice, please.

Post by gravaera »

Combuster wrote:
holypanl wrote:I'm not entirely sure, but lower memory isn't normally needed when an OS goes into full swing. Does Windows or *Nix use lower memory for anything?
Lower memory is just more memory, which is meant to be used. Do you really think common OSes would forego memory that works the same way as higher memory? It also has another advantage: it can be used for ISA DMA transactions.
Great point about the DMA space thing. I suppose I should really do something about that. Although, I wonder how many KB it normally takes to handle a DMA transaction, really? IIRC the DMA has a max num of bytes you can handle at once or something. I haven't read into it extensively yet, though.

Anyway: thanks for the tips peeps.
17:56 < sortie> Paging is called paging because you need to draw it on pages in your notebook to succeed at it.
User avatar
NickJohnson
Member
Member
Posts: 1249
Joined: Tue Mar 24, 2009 8:11 pm
Location: Sunnyvale, California

Re: Max number of processes? Advice, please.

Post by NickJohnson »

Combuster wrote:
holypanl wrote:I'm not entirely sure, but lower memory isn't normally needed when an OS goes into full swing. Does Windows or *Nix use lower memory for anything?
Lower memory is just more memory, which is meant to be used. Do you really think common OSes would forego memory that works the same way as higher memory? It also has another advantage: it can be used for ISA DMA transactions.
But ISA DMA can use the first 16MB of physical memory, not just lower memory. Not to mention that only a couple of devices (i.e. floppy drives) still use ISA DMA, mostly because it sucks.
User avatar
salil_bhagurkar
Member
Member
Posts: 261
Joined: Mon Feb 19, 2007 10:40 am
Location: India

Re: Max number of processes? Advice, please.

Post by salil_bhagurkar »

IMHO using linked lists for process control blocks is the best thing to do. There is no pressing need to go for arrays, as the way a scheduler would schedule processes doesn't need you to optimize by doing arrays, unless you are concerned of the sole advantage of fast pid lookups.

Having arrays also means that you would have to keep track of empty locations in the array when processes are removed. This entire process i think, would be much simpler in a linked list.

When you have linked lists, the limit of number of processes would naturally be limited by the resource: memory. You don't have to worry about number of processes. IIRC, unix uses the 16 bit pid for unix compatibility and hence in your OS, you can have as many processes possible as you want.
Post Reply