* Kernel memory
@ 2001-08-02 8:02 Ginny E. Kim
2001-08-02 13:01 ` Bob Harris
0 siblings, 1 reply; 8+ messages in thread
From: Ginny E. Kim @ 2001-08-02 8:02 UTC (permalink / raw)
--------------------
#if defined(__DECC) && __DECC_VER >= 50860003
#define FINDINDEX(size) (__builtin_isconstant(size) ?
BUCKETINDEX(size) : -1)
#else
#define FINDINDEX(size) BUCKETINDEX(size)
#endif
#define MALLOC(space, cast, size, type, flags) \
(space) = (cast)malloc((u_long)(size), FINDINDEX(size), type,
flags)
int statesize = 5737;
static state_t **table = NULL;
int table_init()
{
MALLOC(table, state_t **, sizeof(state_t *) * statesize,
M_TEMP, M_NOWAIT);
if (table != NULL)
bzero((char *)table, statesize * sizeof(state_t *));
else {
return -1;
}
......................
}
-------------------------------------------
In this case, if statesize is 5737, I can't have the system to
allocate memory using MALLOC. if statesize is 127 or 100, system can
allocate memory using MALLOC.
This program is a part of the loadable kernel module in Tru64UNIX 5.1.
Do Tru64UNIX V5.1 have the option that kernel memory to be allocate is
limited?
If then, how can it be increased?
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: Kernel memory
2001-08-02 8:02 Kernel memory Ginny E. Kim
@ 2001-08-02 13:01 ` Bob Harris
2001-08-03 4:55 ` Ginny E. Kim
0 siblings, 1 reply; 8+ messages in thread
From: Bob Harris @ 2001-08-02 13:01 UTC (permalink / raw)
[[ This message was both posted and mailed: see
the "To," "Cc," and "Newsgroups" headers for details. ]]
In article <2f6bec0a.0108020002.29080aa8@posting.google.com>, Ginny E.
Kim <banny52@yahoo.com> wrote:
X --------------------
X #if defined(__DECC) && __DECC_VER >= 50860003
X #define FINDINDEX(size) (__builtin_isconstant(size) ?
X BUCKETINDEX(size) : -1)
X #else
X #define FINDINDEX(size) BUCKETINDEX(size)
X #endif
X
X #define MALLOC(space, cast, size, type, flags) \
X (space) = (cast)malloc((u_long)(size), FINDINDEX(size), type,
X flags)
X
X
X int statesize = 5737;
X static state_t **table = NULL;
X
X int table_init()
X {
X MALLOC(table, state_t **, sizeof(state_t *) * statesize,
X M_TEMP, M_NOWAIT);
X if (table != NULL)
X bzero((char *)table, statesize * sizeof(state_t *));
X else {
X return -1;
X }
X ......................
X }
X -------------------------------------------
X
X In this case, if statesize is 5737, I can't have the system to
X allocate memory using MALLOC. if statesize is 127 or 100, system can
X allocate memory using MALLOC.
X This program is a part of the loadable kernel module in Tru64UNIX 5.1.
X Do Tru64UNIX V5.1 have the option that kernel memory to be allocate is
X limited?
X If then, how can it be increased?
MALLOC is used when the size of the storage can be specified as either
a hard coded constant, a #define contant, or a sizeof(...) constant.
MALLOC_VAR is used when the size of the storage is passed as a
variable. 'statesize' is a variable and thus you should be using
MALLOC_VAR
Bob Harris
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: Kernel memory
2001-08-02 13:01 ` Bob Harris
@ 2001-08-03 4:55 ` Ginny E. Kim
2001-08-03 13:43 ` Brian Haley
0 siblings, 1 reply; 8+ messages in thread
From: Ginny E. Kim @ 2001-08-03 4:55 UTC (permalink / raw)
Bob Harris <harris@zk3.dec.com> wrote in message news:<020820010901584492%harris@zk3.dec.com>...
> [[ This message was both posted and mailed: see
> the "To," "Cc," and "Newsgroups" headers for details. ]]
>
> In article <2f6bec0a.0108020002.29080aa8@posting.google.com>, Ginny E.
> Kim <banny52@yahoo.com> wrote:
>
> X --------------------
> X #if defined(__DECC) && __DECC_VER >= 50860003
> X #define FINDINDEX(size) (__builtin_isconstant(size) ?
> X BUCKETINDEX(size) : -1)
> X #else
> X #define FINDINDEX(size) BUCKETINDEX(size)
> X #endif
> X
> X #define MALLOC(space, cast, size, type, flags) \
> X (space) = (cast)malloc((u_long)(size), FINDINDEX(size), type,
> X flags)
> X
> X
> X int statesize = 5737;
> X static state_t **table = NULL;
> X
> X int table_init()
> X {
> X MALLOC(table, state_t **, sizeof(state_t *) * statesize,
> X M_TEMP, M_NOWAIT);
> X if (table != NULL)
> X bzero((char *)table, statesize * sizeof(state_t *));
> X else {
> X return -1;
> X }
> X ......................
> X }
> X -------------------------------------------
> X
> X In this case, if statesize is 5737, I can't have the system to
> X allocate memory using MALLOC. if statesize is 127 or 100, system can
> X allocate memory using MALLOC.
> X This program is a part of the loadable kernel module in Tru64UNIX 5.1.
> X Do Tru64UNIX V5.1 have the option that kernel memory to be allocate is
> X limited?
> X If then, how can it be increased?
>
> MALLOC is used when the size of the storage can be specified as either
> a hard coded constant, a #define contant, or a sizeof(...) constant.
>
> MALLOC_VAR is used when the size of the storage is passed as a
> variable. 'statesize' is a variable and thus you should be using
> MALLOC_VAR
>
> Bob Harris
I used the size of the storage of MALLOC be specified as a hard coded constant.
For instance,
#define STATESIZE 5737
statesize = STATESIZE
I don't think 'statesize' is a variable.
MALLOC() in Tru64 V4.0F doesn't have this problem.
Doesn't the type or flag of malloc() have the problem?
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: Kernel memory
2001-08-03 4:55 ` Ginny E. Kim
@ 2001-08-03 13:43 ` Brian Haley
2001-08-04 6:32 ` Ginny E. Kim
0 siblings, 1 reply; 8+ messages in thread
From: Brian Haley @ 2001-08-03 13:43 UTC (permalink / raw)
"Ginny E. Kim" wrote:
> > X int statesize = 5737;
> > X static state_t **table = NULL;
> > X
> > X int table_init()
> > X {
> > X MALLOC(table, state_t **, sizeof(state_t *) * statesize,
> > X M_TEMP, M_NOWAIT);
> > X ......................
> > X }
> >
> > MALLOC is used when the size of the storage can be specified as either
> > a hard coded constant, a #define contant, or a sizeof(...) constant.
> >
> > MALLOC_VAR is used when the size of the storage is passed as a
> > variable. 'statesize' is a variable and thus you should be using
> > MALLOC_VAR
> >
> > Bob Harris
>
> I used the size of the storage of MALLOC be specified as a hard coded constant.
> For instance,
> #define STATESIZE 5737
> statesize = STATESIZE
> I don't think 'statesize' is a variable.
> MALLOC() in Tru64 V4.0F doesn't have this problem.
> Doesn't the type or flag of malloc() have the problem?
Bob is absolutely right here, your code has a bug. 'statesize' is a global
variable, this means its value can be modified, for example with dbx.
For this reason, 'sizeof(state_t *) * statesize' cannot be calculated at
compile time, which is what's required if you're using MALLOC.
You have had a lot of questions here lately, most of which can be
answered by reading the documentation. Please re-read some of it
again, you will probably notice a lot of things you didn't see the
first time now that you've had a chance to write some code.
-Brian
---------------------------------------------------
Brian P. Haley Brian.Haley@compaq.com
Tru64 UNIX Networking Group
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: Kernel memory
2001-08-03 13:43 ` Brian Haley
@ 2001-08-04 6:32 ` Ginny E. Kim
2001-08-10 15:48 ` Brian Haley
0 siblings, 1 reply; 8+ messages in thread
From: Ginny E. Kim @ 2001-08-04 6:32 UTC (permalink / raw)
Brian Haley <haley@zk3.dec.com> wrote in message news:<3B6AAA99.4E07EB07@zk3.dec.com>...
> "Ginny E. Kim" wrote:
>
> > > X int statesize = 5737;
> > > X static state_t **table = NULL;
> > > X
> > > X int table_init()
> > > X {
> > > X MALLOC(table, state_t **, sizeof(state_t *) * statesize,
> > > X M_TEMP, M_NOWAIT);
> > > X ......................
> > > X }
> > >
> > > MALLOC is used when the size of the storage can be specified as either
> > > a hard coded constant, a #define contant, or a sizeof(...) constant.
> > >
> > > MALLOC_VAR is used when the size of the storage is passed as a
> > > variable. 'statesize' is a variable and thus you should be using
> > > MALLOC_VAR
> > >
> > > Bob Harris
> >
> > I used the size of the storage of MALLOC be specified as a hard coded constant.
> > For instance,
> > #define STATESIZE 5737
> > statesize = STATESIZE
> > I don't think 'statesize' is a variable.
> > MALLOC() in Tru64 V4.0F doesn't have this problem.
> > Doesn't the type or flag of malloc() have the problem?
>
> Bob is absolutely right here, your code has a bug. 'statesize' is a global
> variable, this means its value can be modified, for example with dbx.
> For this reason, 'sizeof(state_t *) * statesize' cannot be calculated at
> compile time, which is what's required if you're using MALLOC.
>
> You have had a lot of questions here lately, most of which can be
> answered by reading the documentation. Please re-read some of it
> again, you will probably notice a lot of things you didn't see the
> first time now that you've had a chance to write some code.
>
> -Brian
>
>
> ---------------------------------------------------
> Brian P. Haley Brian.Haley@compaq.com
> Tru64 UNIX Networking Group
I used MALLOC_VAR(), but, I got same result such as MALLOC()....
Is there any other solution like increasing kernel memory?
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: Kernel memory
2001-08-04 6:32 ` Ginny E. Kim
@ 2001-08-10 15:48 ` Brian Haley
2001-08-13 5:21 ` Ginny E. Kim
0 siblings, 1 reply; 8+ messages in thread
From: Brian Haley @ 2001-08-10 15:48 UTC (permalink / raw)
"Ginny E. Kim" wrote:
>
> > > > X int table_init()
> > > > X {
> > > > X MALLOC(table, state_t **, sizeof(state_t *) * statesize,
> > > > X M_TEMP, M_NOWAIT);
> > > > X ......................
> > > > X }
>
> I used MALLOC_VAR(), but, I got same result such as MALLOC()....
> Is there any other solution like increasing kernel memory?
Well, you are using the M_NOWAIT flag, which tells malloc that if it
can't fulfill your request *immediately* then it must return NULL.
Can you change it to use M_WAITOK?
-Brian
-----------------------------------------------
Brian P. Haley
Tru64 UNIX Networking Group
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: Kernel memory
2001-08-10 15:48 ` Brian Haley
@ 2001-08-13 5:21 ` Ginny E. Kim
2001-08-13 18:47 ` Brian Haley
0 siblings, 1 reply; 8+ messages in thread
From: Ginny E. Kim @ 2001-08-13 5:21 UTC (permalink / raw)
Brian Haley <haley@zk3.dec.com> wrote in message news:<3B74026A.827F3D4F@zk3.dec.com>...
> "Ginny E. Kim" wrote:
>
> >
> > > > > X int table_init()
> > > > > X {
> > > > > X MALLOC(table, state_t **, sizeof(state_t *) * statesize,
> > > > > X M_TEMP, M_NOWAIT);
> > > > > X ......................
> > > > > X }
> >
> > I used MALLOC_VAR(), but, I got same result such as MALLOC()....
> > Is there any other solution like increasing kernel memory?
>
> Well, you are using the M_NOWAIT flag, which tells malloc that if it
> can't fulfill your request *immediately* then it must return NULL.
> Can you change it to use M_WAITOK?
>
> -Brian
>
> -----------------------------------------------
> Brian P. Haley
> Tru64 UNIX Networking Group
Thank you for your advice.
I figured out using M_WAITOK. what's difference of two within kernel?
M_NOWAIT option has no problem.
Can you explain their meaning more detaily, or recommend related documents?
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: Kernel memory
2001-08-13 5:21 ` Ginny E. Kim
@ 2001-08-13 18:47 ` Brian Haley
0 siblings, 0 replies; 8+ messages in thread
From: Brian Haley @ 2001-08-13 18:47 UTC (permalink / raw)
"Ginny E. Kim" wrote:
> > Well, you are using the M_NOWAIT flag, which tells malloc that if it
> > can't fulfill your request *immediately* then it must return NULL.
> > Can you change it to use M_WAITOK?
>
> Thank you for your advice.
> I figured out using M_WAITOK. what's difference of two within kernel?
> M_NOWAIT option has no problem.
> Can you explain their meaning more detaily, or recommend related documents?
I thought my last response clarified the difference...
M_NOWAIT == I cannot wait for memory
M_WAITOK == I can wait for memory
You shouldn't ever wait for memory in critical code paths or while
holding simple locks. I don't have time to search the documentation
for a more detailed explanation.
-Brian
-------------------------------------------------
Brian P. Haley
Tru64 UNIX Networking Group
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2001-08-13 18:47 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-08-02 8:02 Kernel memory Ginny E. Kim
2001-08-02 13:01 ` Bob Harris
2001-08-03 4:55 ` Ginny E. Kim
2001-08-03 13:43 ` Brian Haley
2001-08-04 6:32 ` Ginny E. Kim
2001-08-10 15:48 ` Brian Haley
2001-08-13 5:21 ` Ginny E. Kim
2001-08-13 18:47 ` Brian Haley
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox