From: Andrew Morton <akpm@linux-foundation.org>
To: Warren Xiong <warren.xiong@ugreen.com>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] tools/mm: prevent page_owner_sort from truncating input
Date: Wed, 29 Jul 2026 17:31:38 -0700 [thread overview]
Message-ID: <20260729173138.fbc115b5285e1b465b055de7@linux-foundation.org> (raw)
In-Reply-To: <20260729053812.882137-1-warren.xiong@ugreen.com>
On Wed, 29 Jul 2026 13:38:12 +0800 Warren Xiong <warren.xiong@ugreen.com> wrote:
> page_owner_sort opens the output file with "w" before reading the input.
> If both paths refer to the same file, this truncates the input and the
> tool silently processes zero records before returning success.
Don't do that then? I mean, is there any expectation that this works?
hp2:/usr/src/25> ls -l x
-rw-rw-r-- 1 akpm akpm 55318 Jul 29 17:27 x
hp2:/usr/src/25> sort -o x x
hp2:/usr/src/25> ls -l x
-rw-rw-r-- 1 akpm akpm 55318 Jul 29 17:27 x
Oh. sort(1) does that. I never knew.
> Open the output without truncating it and compare the device and inode
> numbers of the opened files. Reject matching regular files, then truncate
> regular output files only after the check. This also detects hard link and
> symbolic link aliases while preserving non-regular outputs such as
> /dev/stdout.
This all sounds complex. How does sort(1) do it? Write to a temporary
file then a rename?
For page_owner_sort I expect we could load all the input into memory
before opening the output file?
next prev parent reply other threads:[~2026-07-30 0:31 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-29 5:38 Warren Xiong
2026-07-30 0:31 ` Andrew Morton [this message]
2026-07-30 1:30 ` 熊卧龙
2026-07-30 1:58 ` [PATCH v2] " Warren Xiong
2026-07-30 20:45 ` Andrew Morton
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=20260729173138.fbc115b5285e1b465b055de7@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=warren.xiong@ugreen.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®