mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Manfred Spraul <manfred@colorfullife.com>
To: Oleg Nesterov <oleg@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	WangYuli <wangyuli@uniontech.com>,
	linux-fsdevel <linux-fsdevel@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Christian Brauner <brauner@kernel.org>
Subject: Re: [RESEND PATCH] fs/pipe: Introduce a check to skip sleeping processes during pipe read/write
Date: Sat, 28 Dec 2024 19:53:57 +0100	[thread overview]
Message-ID: <8d56b9d7-bb92-4c6e-ba8b-da3ec238943b@colorfullife.com> (raw)
In-Reply-To: <20241228163231.GA19293@redhat.com>

Hi Oleg,

On 12/28/24 5:32 PM, Oleg Nesterov wrote:
> On 12/28, Oleg Nesterov wrote:
>> If nothing else, consider
>>
>> 	int CONDITION;
>> 	wait_queue_head_t WQ;
>>
>> 	void wake(void)
>> 	{
>> 		CONDITION = 1;
>> 		wake_up(WQ);
>> 	}
>>
>> 	void wait(void)
>> 	{
>> 		DEFINE_WAIT_FUNC(entry, woken_wake_function);
>>
>> 		add_wait_queue(WQ, entry);
>> 		if (!CONDITION)
>> 			wait_woken(entry, ...);
>> 		remove_wait_queue(WQ, entry);
>> 	}
>>
>> this code is correct even if LOAD(CONDITION) can leak into the critical
>> section in add_wait_queue(), so CPU running wait() can actually do
>>
>> 		// add_wait_queue
>> 		spin_lock(WQ->lock);
>> 		LOAD(CONDITION);	// false!
>> 		list_add(entry, head);
>> 		spin_unlock(WQ->lock);
>>
>> 		if (!false)		// result of the LOAD above
>> 			wait_woken(entry, ...);
>>
>> Now suppose that another CPU executes wake() between LOAD(CONDITION)
>> and list_add(entry, head). With your patch wait() will miss the event.
>> The same for __pollwait(), I think...
>>
>> No?
> Even simpler,
>
> 	void wait(void)
> 	{
> 		DEFINE_WAIT(entry);
>
> 		__set_current_state(XXX);
> 		add_wait_queue(WQ, entry);
>
> 		if (!CONDITION)
> 			schedule();
>
> 		remove_wait_queue(WQ, entry);
> 		__set_current_state(TASK_RUNNING);
> 	}
>
> This code is ugly but currently correct unless I am totally confused.

It is a chance of the add_wait_queue() path, thus impact on all calls.

With (busybox) "find /sys /proc | grep aaaabbbccc", I've seen 16385 
wakeup calls with empty queue, and just 6 with an entry in the queue.

But on other workloads, the ratio was more something like 75% 
empty/25%with entries.

I.e.: We would have long discussions if the change only helps for some 
usecases, and might have negative impact on other use cases.


And: Your proposal is in conflict with

https://git.kernel.org/pub/scm/linux/kernel/git/tglx/history.git/commit/kernel/fork.c?h=v2.6.0&id=e220fdf7a39b54a758f4102bdd9d0d5706aa32a7 


But I do not see the issue, the worst possible scenario should be something like:

	// add_wait_queue
		spin_lock(WQ->lock);
		LOAD(CONDITION);	// false!
		list_add(entry, head);
		STORE(current_state)
		spin_unlock(WQ->lock);


--

     Manfred


  reply	other threads:[~2024-12-28 18:54 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-25  9:42 WangYuli
2024-12-25 13:30 ` Andy Shevchenko
2024-12-25 13:53   ` Kent Overstreet
2024-12-25 16:04     ` Mateusz Guzik
2024-12-25 16:32       ` Kent Overstreet
2024-12-25 17:22         ` Mateusz Guzik
2024-12-25 17:41           ` Kent Overstreet
2024-12-25 15:42   ` WangYuli
2024-12-25 16:00     ` Willy Tarreau
2024-12-25 16:32       ` WangYuli
2024-12-25 16:56         ` Willy Tarreau
2024-12-26 16:00 ` Oleg Nesterov
2024-12-26 19:02 ` Linus Torvalds
2024-12-26 20:11   ` Oleg Nesterov
2024-12-26 20:29     ` Linus Torvalds
2024-12-26 20:57       ` Oleg Nesterov
2024-12-27 15:54         ` Oleg Nesterov
2024-12-27 16:43           ` Oleg Nesterov
2024-12-27 18:39     ` Manfred Spraul
2024-12-28 14:32       ` Oleg Nesterov
2024-12-28 15:22         ` Oleg Nesterov
2024-12-28 16:32           ` Oleg Nesterov
2024-12-28 18:53             ` Manfred Spraul [this message]
2024-12-29 11:54               ` Oleg Nesterov
2024-12-28 16:45           ` Manfred Spraul
2024-12-29 11:57             ` Oleg Nesterov
2024-12-29 12:41               ` Manfred Spraul
2024-12-29 13:05                 ` Oleg Nesterov
2024-12-29 13:13                   ` Oleg Nesterov
2024-12-29 19:54                     ` Manfred Spraul
2024-12-30 15:38                       ` Oleg Nesterov
2024-12-31 11:14                         ` Manfred Spraul
2024-12-31 19:38                           ` Linus Torvalds
2024-12-31 20:24                             ` Oleg Nesterov
2024-12-31 22:31                               ` Linus Torvalds
2025-01-02 13:57                                 ` Oleg Nesterov
2025-01-04 21:15                         ` RFC: Checkpatch: Introduce list of functions that need memory barriers Manfred Spraul

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=8d56b9d7-bb92-4c6e-ba8b-da3ec238943b@colorfullife.com \
    --to=manfred@colorfullife.com \
    --cc=brauner@kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oleg@redhat.com \
    --cc=torvalds@linux-foundation.org \
    --cc=wangyuli@uniontech.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®