From patchwork Tue Sep 5 21:42:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13375096 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 0E327CA100D for ; Tue, 5 Sep 2023 21:42:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 895758E000E; Tue, 5 Sep 2023 17:42:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8417B8E000B; Tue, 5 Sep 2023 17:42:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6BC788E000E; Tue, 5 Sep 2023 17:42:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 595A08E000B for ; Tue, 5 Sep 2023 17:42:49 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 32917A0AFC for ; Tue, 5 Sep 2023 21:42:49 +0000 (UTC) X-FDA: 81203868858.19.6C7D920 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf26.hostedemail.com (Postfix) with ESMTP id 2BBA6140006 for ; Tue, 5 Sep 2023 21:42:46 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=IwdjEhtT; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf26.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1693950167; 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:dkim-signature; bh=BAc+MDavbWwJ6795LOxgDkxGvxMJL+vGI+ILCcyBkDQ=; b=drM/L2uJYUrl0gzl2OFpwzeVavTWk26sALwhubrSZkP1G3CpS8mbMKxevsXjnMap8JHo2e toJ2v8wAB+JlJutMYkpMhpUH8s250NO2mns41rIDLBruhFE/U9ldLu8C6ofmmpnCxAaPsE 6hz5avmNB5ppnxsltGv0E9mhjINJzb4= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=IwdjEhtT; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf26.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1693950167; a=rsa-sha256; cv=none; b=wL8zbomYoKJofAeb/8csjRyiHGF+XXqya+CO+v5l004YaMC+7Hoq2qjVWHO79Qo7dNgvAd VOPsibQPgWBq0CQBXSBXnCl6sW/l9C9dcqOPS47cdBN32B2RH4PwZbBOXP3hD4LGMpRbWi /HMlYQ6m7XLSNUKlRrNrPnL+732wq/Y= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693950166; h=from:from: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=BAc+MDavbWwJ6795LOxgDkxGvxMJL+vGI+ILCcyBkDQ=; b=IwdjEhtTpozqlt8KK3QPPWfb7w4CZnevm2Dy5pqlKnjmAU7CU3rl0PJtkD6skra+GGBbpT JRJGX0q0e07pq9WNkcYfPIOjcgsg5rZxwPI8UC9DD3f0HqPtyG/iqPgJs5vB4xIgoemSsJ r3W5uP9EhR797jze5FMlkVb7IIRL7v0= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-321-mDyZQ1UrOnGcHHP7QSNkpA-1; Tue, 05 Sep 2023 17:42:42 -0400 X-MC-Unique: mDyZQ1UrOnGcHHP7QSNkpA-1 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-7708c1ae500so2639485a.0 for ; Tue, 05 Sep 2023 14:42:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693950162; x=1694554962; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BAc+MDavbWwJ6795LOxgDkxGvxMJL+vGI+ILCcyBkDQ=; b=le5k+6EEa7O9+fzVetA1Jg6278l3gxFgvS69AnrqJUGHRCGSji/8tH2j/Kj4+XHD1p yVUF+qoKpJAJl5+KZXdyuzp1kmZ2+usc/HDJqs+JmfaUMotKkPXQJ7ENl8Gv7bHd1msT 2WyvbjESSSe+NVHo7vDw/0EILJwsLnmrALjqPfywnU0UmSjFjdk84vhfMAsvaetkSevb VshWzPkNW1rGJwWjzdDN6SBbtodhlT3ZpiX6xwJlF+xTxut/BF1shT2PcLfFHPgoXrLv RDZ2hNuXYtq8bftYzQ9IURiktVf+za701oT/1HeAJQqB2dvZ3c6DHPG0QN6XGpL216nz FZJQ== X-Gm-Message-State: AOJu0YxWFQ5oqjrWO1okuTahLPJ093dZ1o6or9wY8/E4svuDa8cF3PbE 7zvQ28udnQnV1YnQtgI2G/4ie4E7/1EzaR78r7bgLYRd2XYIF2DGazPXzgfS7lO0Z3fUz3UknkF FIy7uafft9cORYSQa+1c= X-Received: by 2002:a05:620a:1a26:b0:76c:ed4e:ac10 with SMTP id bk38-20020a05620a1a2600b0076ced4eac10mr16770014qkb.6.1693950161775; Tue, 05 Sep 2023 14:42:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHX81eRpvF4K65o6If4EOmXGS0BgJwHt7s35QflxCMt79X+rblwCZ36Xulk34UDBuMUSImVnw== X-Received: by 2002:a05:620a:1a26:b0:76c:ed4e:ac10 with SMTP id bk38-20020a05620a1a2600b0076ced4eac10mr16769997qkb.6.1693950161469; Tue, 05 Sep 2023 14:42:41 -0700 (PDT) Received: from x1n.redhat.com (cpe5c7695f3aee0-cm5c7695f3aede.cpe.net.cable.rogers.com. [99.254.144.39]) by smtp.gmail.com with ESMTPSA id i2-20020a37c202000000b007682af2c8aasm4396938qkm.126.2023.09.05.14.42.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Sep 2023 14:42:41 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Anish Moorthy , Axel Rasmussen , Alexander Viro , Mike Kravetz , Peter Zijlstra , Andrew Morton , Mike Rapoport , Christian Brauner , peterx@redhat.com, linux-fsdevel@vger.kernel.org, Andrea Arcangeli , Ingo Molnar , James Houghton , Nadav Amit Subject: [PATCH 3/7] poll: POLL_ENQUEUE_EXCLUSIVE Date: Tue, 5 Sep 2023 17:42:31 -0400 Message-ID: <20230905214235.320571-4-peterx@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230905214235.320571-1-peterx@redhat.com> References: <20230905214235.320571-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Queue-Id: 2BBA6140006 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: 5m8nekbjhwthkrc3o83me6sn4nwxq9dx X-HE-Tag: 1693950166-43682 X-HE-Meta: U2FsdGVkX18OQEZw/rMJcnV9t7cdWk8TjEJr0nmera5Bc5l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qiuLIv8uvWtI09RDOy2q1zEYaMdThnc7AM3GWqSrkcSxeVNDvaWMdKUss304VpIhbRzEHJJKewD+z1fra6QPV9Z8H1gsXtZTWlt7W1G9zHRFisfjCaYturZPWS6nk3Z5fV/84xPhf+gHjskeGYRHxx5zybscEiVqeM3BAZSoOelhv66QqeilS7vwm8qs6oKpTxhAPI0nlSpgA0t7jH7DSvlZidid/t+eUScwhKUFxcF2JuLrflEXEnfJq4PuGE3rSS+gFpyePKnHoFnVb3iFRvZM2Hu6/8mXPaOlc2DGqi1iAzhOXIyoF87g6Bvyxdx6HBrYXe6lCjusH2xreaz4pJ37b4T2dO+lImr7hRFTJW6/0FofHj 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: Add a flag for poll_wait() showing that the caller wants the enqueue to be exclusive. It is similar to EPOLLEXCLUSIVE for epoll() but grants kernel poll users to opt-in with more efficient exclusive queuing where applicable. Signed-off-by: Peter Xu --- fs/select.c | 5 ++++- include/linux/poll.h | 20 ++++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/fs/select.c b/fs/select.c index 0433448481e9..a3c9088e8d76 100644 --- a/fs/select.c +++ b/fs/select.c @@ -231,7 +231,10 @@ static void __pollwait(struct file *filp, wait_queue_head_t *wait_address, entry->key = p->_key; init_waitqueue_func_entry(&entry->wait, pollwake); entry->wait.private = pwq; - add_wait_queue(wait_address, &entry->wait); + if (flags & POLL_ENQUEUE_EXCLUSIVE) + add_wait_queue_exclusive(wait_address, &entry->wait); + else + add_wait_queue(wait_address, &entry->wait); } static int poll_schedule_timeout(struct poll_wqueues *pwq, int state, diff --git a/include/linux/poll.h b/include/linux/poll.h index cbad520fc65c..11af98ae579c 100644 --- a/include/linux/poll.h +++ b/include/linux/poll.h @@ -29,6 +29,8 @@ typedef unsigned int poll_flags; +#define POLL_ENQUEUE_EXCLUSIVE BIT(0) + struct poll_table_struct; /* @@ -46,10 +48,24 @@ typedef struct poll_table_struct { __poll_t _key; } poll_table; -static inline void poll_wait(struct file * filp, wait_queue_head_t * wait_address, poll_table *p) +static inline void __poll_wait(struct file *filp, wait_queue_head_t *wait_address, + poll_table *p, poll_flags flags) { if (p && p->_qproc && wait_address) - p->_qproc(filp, wait_address, p, 0); + p->_qproc(filp, wait_address, p, flags); +} + +static inline void poll_wait(struct file *filp, wait_queue_head_t *wait_address, + poll_table *p) +{ + __poll_wait(filp, wait_address, p, 0); +} + +static inline void poll_wait_exclusive(struct file *filp, + wait_queue_head_t *wait_address, + poll_table *p) +{ + __poll_wait(filp, wait_address, p, POLL_ENQUEUE_EXCLUSIVE); } /*