From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A9C00EB64D8 for ; Wed, 21 Jun 2023 13:33:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 469C78D0006; Wed, 21 Jun 2023 09:33:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 419568D0003; Wed, 21 Jun 2023 09:33:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 308FD8D0006; Wed, 21 Jun 2023 09:33:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 203898D0003 for ; Wed, 21 Jun 2023 09:33:12 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id CCD8C1C80E6 for ; Wed, 21 Jun 2023 13:33:11 +0000 (UTC) X-FDA: 80926846182.03.5EF09D9 Received: from www262.sakura.ne.jp (www262.sakura.ne.jp [202.181.97.72]) by imf15.hostedemail.com (Postfix) with ESMTP id 0705CA001F for ; Wed, 21 Jun 2023 13:33:07 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=none; dmarc=none; spf=none (imf15.hostedemail.com: domain of penguin-kernel@I-love.SAKURA.ne.jp has no SPF policy when checking 202.181.97.72) smtp.mailfrom=penguin-kernel@I-love.SAKURA.ne.jp ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1687354388; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DkCxFCUC16VyhipXjlb7zBtRjwLfhNeSF77qZHCmQRU=; b=wd5EHq5y2i41zSNhnaZEg6XiHIPITI8WM6MUao0z6qwc6bfCqvF7UqVHDEfxhxkWiNUp0s UPXY4CkD4HKuKnftXHHkzJP/t1EJWyZTI81q0lpgnOTMqxXSk7S3JgpUfV9y9hFOrGSg/s UtsBxzkvo+J5QLb6znQe+22cBmBjuw4= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=none; dmarc=none; spf=none (imf15.hostedemail.com: domain of penguin-kernel@I-love.SAKURA.ne.jp has no SPF policy when checking 202.181.97.72) smtp.mailfrom=penguin-kernel@I-love.SAKURA.ne.jp ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687354388; a=rsa-sha256; cv=none; b=wUi9TczFLwpafCXzH4m6GVz12f7PaMSz27FVl+GnZULu98zzpGy2DGCSP6VozY/N4K6tGz tGWz+DGSilNom9zHTELIyqaYcBfLiAjBaWN8mpt7T0nimEeajh4tXbrt0CTMulEDJqLwpn CLPDMt938XIQgso04ljLahcty1bluoY= Received: from fsav313.sakura.ne.jp (fsav313.sakura.ne.jp [153.120.85.144]) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTP id 35LDWgY2074161; Wed, 21 Jun 2023 22:32:42 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) Received: from www262.sakura.ne.jp (202.181.97.72) by fsav313.sakura.ne.jp (F-Secure/fsigk_smtp/550/fsav313.sakura.ne.jp); Wed, 21 Jun 2023 22:32:42 +0900 (JST) X-Virus-Status: clean(F-Secure/fsigk_smtp/550/fsav313.sakura.ne.jp) Received: from [192.168.1.6] (M106072142033.v4.enabler.ne.jp [106.72.142.33]) (authenticated bits=0) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTPSA id 35LDWgIY074154 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NO); Wed, 21 Jun 2023 22:32:42 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) Message-ID: Date: Wed, 21 Jun 2023 22:32:40 +0900 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: Re: [PATCH] mm/page_alloc: Use write_seqlock_irqsave() instead write_seqlock() + local_irq_save(). Content-Language: en-US To: Sebastian Andrzej Siewior Cc: linux-mm@kvack.org, "Luis Claudio R. Goncalves" , Andrew Morton , Mel Gorman , Michal Hocko , Thomas Gleixner , Petr Mladek References: <20230621104034.HT6QnNkQ@linutronix.de> <0e9fc992-8e05-2e63-b3b1-d8d3ce89fc16@I-love.SAKURA.ne.jp> <20230621130641.-5iueY1I@linutronix.de> From: Tetsuo Handa In-Reply-To: <20230621130641.-5iueY1I@linutronix.de> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 0705CA001F X-Stat-Signature: faib77rosw1eaj9qnsjg3sf93fi4i3jf X-HE-Tag: 1687354387-40152 X-HE-Meta: U2FsdGVkX18a+f4ynPFW3AGOcVlCZkzczVFvODh5FApjjOYZD61rqxZPrDvzxI34e2+78kizJXL1jfKUchJVsDQcMHWE+rMbRX/2rj01HtF+OFq8oIQWjBnLOzISy1kJPBnAPePcJl15A0cq9/vdrXywcXo4dYNlym4tqTwUbLtVDgJ3Bduyyf3YKK6Jr3A73wsaj5UmfO/2GZ4ReaZIT4R9hTrtnXlS743LXfudnt7My1uhW0lx7NqouQI9QAOYOyxt1O/cppHChZAGL53kEDSwok0+g3Vg+gIZ+uxaX+NdLkTwnBXvpg6rAShdMbHWX7yVZ4QUfpNrPxdhZ8K9ywNhJgkmYFz64cWjIqSDgFqD7xXmWJrQClR/VpuY9YxrPYD7+M8NKhAF7+WfVTQgxc8vFYJX8TvVRXYPayW8GBYbSmr/W0sH0NLMXQtwXN6YAgc0M3Rh0EcbegHuOsvvdlP1ZTRqHpH0lMZp98HqYdBEAQ2MEUYSqYnxKBDn2Uf6OCoMyy+CA4iyN+2M0FWvR1pD41aFWmwRL+43js0zaK7HjrItMyde2oLIclmWqkEgqsi2Kk9R98ZpYMAu7NPeHI9r9Q6kByWvHWB3zksMM89QRzfqqIOFIj0QIWOqB2jBEQAEdqPgkIIP3YUPD/v/om5n6lcuBDbehS1TKsASKWFgmzasyRy2LG9ZWoxb1zZpHuALhCYWdj9Ivd3Gn9aGLzua6Ne95VJEfIng4111pC7nBfkcKhC/TwIipc013KcogmPryg9ystS4p9O68tJcrRZbbLKQQcw74NV+OnMyQIxTbB+chY+DMKdDZzBfBm0QPySEuY+/BdCZeaBK/snCGCb93sOZb/sQ+Mlood+sknsZbDRnZHonVCzEiWNz7BD4dSmQqLAJoaMaZ9lKnfCNZdY4N85VNGRc7u6yWWdv0Qe12Yhkf7mIRTIXWRsDIaB+3c+zP3tSfAQdoCS7VwH urriG6g/ EzlxmCzdWzUrlFea3X7i/GpCa/HPjo26uNg/FkypHcGlDwRwMyvkf7WtmkF+Z9bFHC7kp5T3/i5xY8LzfI7bUR3SKkkbuS4m9TaoJecYOeatB289O6sRCk/BnQvABOrvZdVBOwkTgN0NRVUaNqiw0h9+KiuBQFFICPAql5NjJGfrabQpHAYn0VA7WURbLumDtlqZ9U2cb1WpYzkaXV53p+D3JDAvTFqHOUCxk82YXroIC9YrBqc+lSMzEx6nHcxYgt4ojGEa8mQuyhNg= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 2023/06/21 22:06, Sebastian Andrzej Siewior wrote: > On 2023-06-21 20:33:35 [+0900], Tetsuo Handa wrote: >> On 2023/06/21 19:40, Sebastian Andrzej Siewior wrote: >>> printk_deferred_enter() has to be invoked in non-migrate-able context to >>> ensure that deferred printing is enabled and disabled on the same CPU. >> >> I can't catch. local_irq_save(flags); makes non-migrate-able context >> because sleeping is not allowed while IRQ is disabled, doesn't it? > > That is correct. The problem is the local_irq_save() which remains on > PREEMPT_RT and this is problematic during write_seqlock() which acquires > spinlock_t which becomes a sleeping lock. write_seqlock_irqsave() > substitutes everything properly so on RT there is no local_irq_save(). include/linux/seqlock.h says static inline unsigned long __write_seqlock_irqsave(seqlock_t *sl) { unsigned long flags; spin_lock_irqsave(&sl->lock, flags); do_write_seqcount_begin(&sl->seqcount.seqcount); return flags; } /** * write_seqlock_irqsave() - start a non-interruptible seqlock_t write * section * @lock: Pointer to seqlock_t * @flags: Stack-allocated storage for saving caller's local interrupt * state, to be passed to write_sequnlock_irqrestore(). * * _irqsave variant of write_seqlock(). Use it only if the read side * section, or other write sections, can be invoked from hardirq context. */ #define write_seqlock_irqsave(lock, flags) \ do { flags = __write_seqlock_irqsave(lock); } while (0) /** * write_seqlock() - start a seqlock_t write side critical section * @sl: Pointer to seqlock_t * * write_seqlock opens a write side critical section for the given * seqlock_t. It also implicitly acquires the spinlock_t embedded inside * that sequential lock. All seqlock_t write side sections are thus * automatically serialized and non-preemptible. * * Context: if the seqlock_t read section, or other write side critical * sections, can be invoked from hardirq or softirq contexts, use the * _irqsave or _bh variants of this function instead. */ static inline void write_seqlock(seqlock_t *sl) { spin_lock(&sl->lock); do_write_seqcount_begin(&sl->seqcount.seqcount); } and regarding include/linux/spinlock.h , since spin_lock_irqsave(lock, flags) is equivalent with local_irq_save(flags) + spin_lock(lock), there is no difference between local_irq_save(flags); printk_deferred_enter(); write_seqlock(&zonelist_update_seq); and write_seqlock_irqsave(&zonelist_update_seq, flags); printk_deferred_enter(); (except potential lockdep warning). However, regarding include/linux/spinlock_rt.h , since spin_lock_irqsave(lock, flags) is equivalent with spin_lock(lock), there is difference between local_irq_save(flags); printk_deferred_enter(); write_seqlock(&zonelist_update_seq); and write_seqlock_irqsave(&zonelist_update_seq, flags); printk_deferred_enter(); . Is above understanding correct? And you are trying to replace local_irq_save(flags); printk_deferred_enter(); write_seqlock(&zonelist_update_seq); with write_seqlock_irqsave(&zonelist_update_seq, flags); printk_deferred_enter(); , aren't you? But include/linux/printk.h says /* * The printk_deferred_enter/exit macros are available only as a hack for * some code paths that need to defer all printk console printing. Interrupts * must be disabled for the deferred duration. */ #define printk_deferred_enter __printk_safe_enter #define printk_deferred_exit __printk_safe_exit which means that local_irq_save() is _required_ before printk_deferred_enter(). If local_irq_save() is hidden by your patch, what guarantees that printk_deferred_enter() and printk_deferred_exit() run on the same CPU? Also, if local_irq_save() is hidden due to RT, what guarantees that write_seqlock_irqsave(&zonelist_update_seq, flags); <> some_timer_function() { printk(); } <> printk_deferred_enter(); does not happen because write_seqlock_irqsave() does not disable IRQ? Disabling IRQ before incrementing zonelist_update_seq is _required_ for both making printk_deferred_enter() safe and making sure that printk_deferred_enter() takes effect .