From: Stanislav Kholmanskikh <stanislav.kholmanskikh@oracle.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH 2/4] memcg_process_stress: allocate memory not in the signal handler
Date: Thu, 12 May 2016 14:09:50 +0300 [thread overview]
Message-ID: <5734647E.2040801@oracle.com> (raw)
In-Reply-To: <20160511143913.GH24701@rei.lan>
Hi!
On 05/11/2016 05:39 PM, Cyril Hrubis wrote:
> Hi!
>> -static void sigusr_handler(int __attribute__ ((unused)) signo)
>> +static void alloc_memory(void)
>> {
>> int i;
>> int pagesize;
>>
>> pagesize = sysconf(_SC_PAGE_SIZE);
>>
>> - nr_page = ceil((double)memsize / pagesize);
>> + nr_page = memsize / pagesize;
>
> This will cause to allocate one less page than the previous code in case
> that memsize % pagesize != 0.
>
> ceil((double)memsize/pagesize) == (memsize + pagesize - 1)/pagesize
>
> In case that you want to avoid floating point.
>
>> pages = calloc(nr_page, sizeof(char *));
>> if (pages == NULL)
>> @@ -62,7 +54,18 @@ static void sigusr_handler(int __attribute__ ((unused)) signo)
>> if (pages[i] == MAP_FAILED)
>> err(1, "mmap");
>> }
>> +}
>>
>> +static void touch_memory(void)
>> +{
>> + int i;
>> +
>> + for (i = 0; i < nr_page; i++)
>> + pages[i][0] = 0xef;
>> +}
>> +
>> +static void sigusr_handler(int __attribute__ ((unused)) signo)
>> +{
>> flag_ready = 1;
>> }
>>
>> @@ -76,6 +79,7 @@ int main(int argc, char *argv[])
>> char *end;
>> struct sigaction sigint_action;
>> struct sigaction sigusr_action;
>> + int allocated = 0;
>>
>> if (argc != 3)
>> errx(1, "wrong argument num");
>> @@ -102,8 +106,14 @@ int main(int argc, char *argv[])
>> while (!flag_exit) {
>> sleep(interval);
>>
>> - if (flag_ready)
>> + if (flag_ready) {
>> + if (!allocated) {
>> + alloc_memory();
>> + allocated = 1;
>> + }
>> +
>> touch_memory();
>> + }
>> }
>
>
> We can do even better if we change the sleep() for pause().
Thank you for the review. I agree with all other comments to this
series, except this one.
I'd keep sleep() here, because it allows the process to perform a series
of touch_memory() invocations before it receives the final SIGINT signal.
>
>> return 0;
>
> Otherwise it looks good.
>
next prev parent reply other threads:[~2016-05-12 11:09 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-22 15:23 [LTP] [PATCH 1/4] memcg_process_stress: cleanup Stanislav Kholmanskikh
2016-04-22 15:23 ` [LTP] [PATCH 2/4] memcg_process_stress: allocate memory not in the signal handler Stanislav Kholmanskikh
2016-04-22 15:23 ` [LTP] [PATCH 3/4] memcg_stress_test.sh: rewrite Stanislav Kholmanskikh
2016-04-22 15:23 ` [LTP] [RFC PATCH 4/4] memcg_stress_test.sh: allocate less than CommitLimit bytes Stanislav Kholmanskikh
2016-05-12 13:42 ` Cyril Hrubis
2016-05-17 12:52 ` Stanislav Kholmanskikh
2016-05-17 13:02 ` Stanislav Kholmanskikh
2016-05-18 14:39 ` Cyril Hrubis
2016-05-18 17:29 ` Stanislav Kholmanskikh
2016-05-19 13:38 ` Cyril Hrubis
2016-05-23 11:12 ` Stanislav Kholmanskikh
2016-05-24 16:46 ` Cyril Hrubis
2016-05-19 9:17 ` Michal Hocko
2016-05-19 12:56 ` Cyril Hrubis
2016-05-19 19:21 ` Michal Hocko
2016-05-24 16:21 ` Cyril Hrubis
2016-05-11 15:01 ` [LTP] [PATCH 3/4] memcg_stress_test.sh: rewrite Cyril Hrubis
2016-05-11 14:39 ` [LTP] [PATCH 2/4] memcg_process_stress: allocate memory not in the signal handler Cyril Hrubis
2016-05-12 11:09 ` Stanislav Kholmanskikh [this message]
2016-05-12 11:26 ` Cyril Hrubis
2016-05-11 14:16 ` [LTP] [PATCH 1/4] memcg_process_stress: cleanup Cyril Hrubis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5734647E.2040801@oracle.com \
--to=stanislav.kholmanskikh@oracle.com \
--cc=ltp@lists.linux.it \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.