From: Petr Vorel <pvorel@suse.cz>
To: Wei Gao <wegao@suse.com>
Cc: "ltp@lists.linux.it" <ltp@lists.linux.it>
Subject: Re: [LTP] [PATCH v1] libswap.c: Improve caculate swap dev number
Date: Tue, 5 Mar 2024 11:15:22 +0100 [thread overview]
Message-ID: <20240305101522.GB3825993@pevik> (raw)
In-Reply-To: <ZeaZLq4tsazFvxuW@wegao.81.247.47>
> On Mon, Mar 04, 2024 at 06:04:08PM +0800, Li Wang wrote:
> > On Mon, Mar 4, 2024 at 5:19 PM Yang Xu (Fujitsu) <xuyang2018.jy@fujitsu.com>
> > wrote:
> > > Hi Li,
> > > > On Sun, Mar 3, 2024 at 9:14 PM Petr Vorel <pvorel@suse.cz
> > > > <mailto:pvorel@suse.cz>> wrote:
> > > > Hi Wei, Xu,
> > > > > Hi Wei
> > > > > > I encounter a dead loop on following code in our test on ppc64
> > > > machine:
> > > > > > while ((c = fgetc(fp)) != EOF)
> > > > > > I think "/proc/swaps" is not normal file and can not get EOF in
> > > > some situation,
> > > > > > so i use fgets a line and caculate swap dev number.
> > > > I guess the problem has been fixed by another patch [1], thus
> > > > closing it in
> > > > patchwork. Please let me know if not.
> > > > Seems not, the patch [1] below is mainly to count the free disk size.
> > > > But Wei's work here is to calculate swap-dev numbers correctly
> > > > (especially get rid of EOF affection to some degree).
> > > > Xu Yang, what do you think? or did I miss anything here?
> > > I still think we can use the same way in ipc libs to get rid of the EOF
> > > problem instead of
> > > searching "dev" keyword. We just don't need to calcualte "/proc/swaps"
> > > header.
> > Sounds good to me. At least it counts right lines.
> > It'd be great to have a patch by that way.
> > > int get_used_sysvipc(const char *file, const int lineno, const char
> > > *sysvipc_file)
> > > {
> > > FILE *fp;
> > > int used = -1;
> > > char buf[BUFSIZE];
> > > fp = safe_fopen(file, lineno, NULL, sysvipc_file, "r");
> > > while (fgets(buf, BUFSIZE, fp) != NULL)
> > > used++;
> > > fclose(fp);
> > > if (used < 0) {
> > > tst_brk(TBROK, "can't read %s to get used sysvipc resource
> > > total at "
> > > "%s:%d", sysvipc_file, file, lineno);
> > > }
> > > return used;
> > > }
> > > But we don't get the actual reason, I still wonder why this deadloop
> > > exists o ppcc64 instead of
> > > other architecture(ie x86_64).
FYI also other architectures fails (eg.g least aarch64, s390x and ppc64le which
was in the original report; it looks to me it works on x86_64).
Problem is somewhere in
c1b8c011e447088b08787462e0c2ed50cd8c43f3..8fd941649afeecc5f87508c9f94e9a840a84e44d
which contains 319693d0b ("libltpswap: alter tst_count_swaps API"), which is Wei
trying to fix.
> > Ok, I think we can just apply your suggested method to see if that deadloop
> > disappears.
> Hi Petr, Xu, Li
> Deadloop will disappear if you use fgets, fgetc can not get EOF on ppc64.(Suspect an bug)
> So either use my patch or Xu's suggestion both can work.
I would vote for Xu's suggestion (any line except the first header is valid),
actually this implementation is not correct when it counts only /dev:
# dd if=/dev/zero of=/root/swap bs=100M count=1
# mkswap -f /root/swap
# swapon /root/swap
# cat /proc/swaps
Filename Type Size Used Priority
/dev/dm-0 partition 192508 4048 -2
/root/swap file 102396 0 -3
(second line without /dev)
Also typo in the subject: s/caculate/calculate/
Wei, please send new version and Cc us.
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2024-03-05 10:15 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-01 6:27 [LTP] [PATCH v1] libswap.c: Improve caculate swap dev number Wei Gao via ltp
2024-03-01 6:45 ` Yang Xu (Fujitsu) via ltp
2024-03-03 13:14 ` Petr Vorel
2024-03-04 8:49 ` Li Wang
2024-03-04 9:04 ` Petr Vorel
2024-03-04 9:18 ` Yang Xu (Fujitsu) via ltp
2024-03-04 10:04 ` Li Wang
2024-03-05 4:01 ` Wei Gao via ltp
2024-03-05 10:15 ` Petr Vorel [this message]
2024-03-05 14:10 ` [LTP] [PATCH v2] libswap.c: Improve calculate " Wei Gao via ltp
2024-03-05 14:45 ` Petr Vorel
2024-03-05 21:04 ` Petr Vorel
2024-03-06 1:32 ` Yang Xu (Fujitsu) via ltp
2024-03-06 9:59 ` Petr Vorel
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=20240305101522.GB3825993@pevik \
--to=pvorel@suse.cz \
--cc=ltp@lists.linux.it \
--cc=wegao@suse.com \
/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.