Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp5995024ybe; Tue, 10 Sep 2019 11:54:03 -0700 (PDT) X-Google-Smtp-Source: APXvYqykZIJ8TjMQhT4VphBVJSFsxRY4mKqxd/bA8xGApooxtg7M6lbh2rn2fPa2SynynAJf7C0Z X-Received: by 2002:a50:f293:: with SMTP id f19mr32498928edm.85.1568141643468; Tue, 10 Sep 2019 11:54:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568141643; cv=none; d=google.com; s=arc-20160816; b=THk0R173LqRVdPHg97GCZl0ap9dz1yMlVPTbeMf1pUKvB5U+cRzi9ZBSoccriGJNlC i4zFAHIBnD2BN5AWMQ0EsJBMpBXWaZSTINgXIXCuYRn1LXs9aYQCEiMsu2dzbPPIJF3n 1b+tVnNR0xAvyd9F5NfrYzECzjdjZyMWDLfzc1RxlGBoZCZEwq01aQiQAj1zahHU6z8f ge4cUHjlv0CzifQtWOM/ASet4rj6myx4W5NK7e0DgEN0iRaoOr3bawMRoL0ES7P/QG/w wiJgL5V+Gt27cX72DbpWIfz2vWghYHGizqWScX95L+cj5TyBoKG4g4FBmDpqy87EcVUx tF9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=pUWhX3ThjBsfsGFjHTg5vM8zbxi9HZ/0nZMiaDbj8tw=; b=CcCsiB8rnZz1yoEoNvLiATcPXc5JO5eqdBQPD7wRDX7BmS9YUI5sGcf6rEmasTAx6l Ac6HVWzwPAphLSxThQwibSU3ImZXeGWfhQUCO4n/kWWsYfd+iNmX2GOpGlE4eSf933C1 /vK1wXCBJMla+WlN8DA74I9J0O9A2/AXySyNZQnjus/ZnL6+1ZA1MvOfAnD1gm/1x7e3 QNwR5s7c8my04TvQoUGNN4xWpqjHhEAde93RpMdDgz/mA9WDfO0LAqP6zWCfY2+0W+Hz Mc/kC3uCZgVNDik66hFjEcrrPwt/8VzPyhpzp4pyEgP44eKxv602ksm4Ssuz6z5V1P88 0Ihg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=GxPXDkYL; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v2si12447823edm.80.2019.09.10.11.53.39; Tue, 10 Sep 2019 11:54:03 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=GxPXDkYL; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391889AbfIJKAE (ORCPT + 99 others); Tue, 10 Sep 2019 06:00:04 -0400 Received: from mail-ed1-f67.google.com ([209.85.208.67]:36980 "EHLO mail-ed1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391894AbfIJKAD (ORCPT ); Tue, 10 Sep 2019 06:00:03 -0400 Received: by mail-ed1-f67.google.com with SMTP id i1so16510578edv.4 for ; Tue, 10 Sep 2019 03:00:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov-name.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=pUWhX3ThjBsfsGFjHTg5vM8zbxi9HZ/0nZMiaDbj8tw=; b=GxPXDkYLjPwpEyC9jWChtUTWeR0/79A5cu90rpnDmM8on2MRXtnBKzG29ORgLNA6f1 txcUcoaQTdyTAiUGkQUZZPJkuD7nugbVl3CoybHPuQAFAMtvHrQNCku4QefgSsIOGT5b GUwbPSSrp+wXw9hrMHdTQNdmUSFac6yQhUk7I67mBDwyM41vxlCITlbm0a6vv00s+fSY qXDIpgTKRMsVg9s5v3fD0Iea3f5IqYCoYeYadWUZdGSt94hYnIyN0FHw7mmmsMZPFsKe 4eW7ii0xEN698uaYMy49yVN+Hursc/82AAUIRsnWjFuvJblw4Boic9ulaxPxCxm0f7Y3 0oLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=pUWhX3ThjBsfsGFjHTg5vM8zbxi9HZ/0nZMiaDbj8tw=; b=mx08OUJTONTGMTrCW301qg5o6zDX9Hq0MpZwOSAPYtK9UAkumTsPGzIlc2zYJPuOUU pPsMmE9MpPWihyiTiEJz14YU7w9xWR6H+DJypHkisSCUhuX+kSO/r0xZlgraecinKAcd 1f74wTiIGmvEqWlzWS2/QfHuP14ZgExAcuDj5MMlmEVpx9k22CUlRLeAEVs1vFc/+NRp xaJ8IjEwa3q5SGvf0OPEUNSzhXJPKiBLfOCC09qf8K28XlZiAjjGdZlvqJT1OMp3kWcR 7zCCvKmsGB/BWyanEU8IrfOJ8R3AwdXOHhaveuG8EvUhcPrw/Dpg/AOyWvHzsenrcAp1 8k1g== X-Gm-Message-State: APjAAAVKNNvPXGkrQG6m+8IiKvIubpRiSzyqSmJrDblxh+aVStpi0rgZ DpZnJ5Ymdbe2z5ppqpwl16kP9Q== X-Received: by 2002:a17:906:5f84:: with SMTP id a4mr23374522eju.109.1568109601468; Tue, 10 Sep 2019 03:00:01 -0700 (PDT) Received: from box.localdomain ([86.57.175.117]) by smtp.gmail.com with ESMTPSA id a55sm3486246edd.34.2019.09.10.03.00.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Sep 2019 03:00:00 -0700 (PDT) Received: by box.localdomain (Postfix, from userid 1000) id E0B701009F6; Tue, 10 Sep 2019 13:00:00 +0300 (+03) Date: Tue, 10 Sep 2019 13:00:00 +0300 From: "Kirill A. Shutemov" To: Mike Christie Cc: axboe@kernel.dk, James.Bottomley@HansenPartnership.com, martin.petersen@oracle.com, linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org, linux-block@vger.kernel.org Subject: Re: [RFC PATCH] Add proc interface to set PF_MEMALLOC flags Message-ID: <20190910100000.mcik63ot6o3dyzjv@box.shutemov.name> References: <20190909162804.5694-1-mchristi@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190909162804.5694-1-mchristi@redhat.com> User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Sep 09, 2019 at 11:28:04AM -0500, Mike Christie wrote: > There are several storage drivers like dm-multipath, iscsi, and nbd that > have userspace components that can run in the IO path. For example, > iscsi and nbd's userspace deamons may need to recreate a socket and/or > send IO on it, and dm-multipath's daemon multipathd may need to send IO > to figure out the state of paths and re-set them up. > > In the kernel these drivers have access to GFP_NOIO/GFP_NOFS and the > memalloc_*_save/restore functions to control the allocation behavior, > but for userspace we would end up hitting a allocation that ended up > writing data back to the same device we are trying to allocate for. > > This patch allows the userspace deamon to set the PF_MEMALLOC* flags > through procfs. It currently only supports PF_MEMALLOC_NOIO, but > depending on what other drivers and userspace file systems need, for > the final version I can add the other flags for that file or do a file > per flag or just do a memalloc_noio file. > > Signed-off-by: Mike Christie > --- > Documentation/filesystems/proc.txt | 6 ++++ > fs/proc/base.c | 53 ++++++++++++++++++++++++++++++ > 2 files changed, 59 insertions(+) > > diff --git a/Documentation/filesystems/proc.txt b/Documentation/filesystems/proc.txt > index 99ca040e3f90..b5456a61a013 100644 > --- a/Documentation/filesystems/proc.txt > +++ b/Documentation/filesystems/proc.txt > @@ -46,6 +46,7 @@ Table of Contents > 3.10 /proc//timerslack_ns - Task timerslack value > 3.11 /proc//patch_state - Livepatch patch operation state > 3.12 /proc//arch_status - Task architecture specific information > + 3.13 /proc//memalloc - Control task's memory reclaim behavior > > 4 Configuring procfs > 4.1 Mount options > @@ -1980,6 +1981,11 @@ Example > $ cat /proc/6753/arch_status > AVX512_elapsed_ms: 8 > > +3.13 /proc//memalloc - Control task's memory reclaim behavior > +----------------------------------------------------------------------- > +A value of "noio" indicates that when a task allocates memory it will not > +reclaim memory that requires starting phisical IO. > + > Description > ----------- > > diff --git a/fs/proc/base.c b/fs/proc/base.c > index ebea9501afb8..c4faa3464602 100644 > --- a/fs/proc/base.c > +++ b/fs/proc/base.c > @@ -1223,6 +1223,57 @@ static const struct file_operations proc_oom_score_adj_operations = { > .llseek = default_llseek, > }; > > +static ssize_t memalloc_read(struct file *file, char __user *buf, size_t count, > + loff_t *ppos) > +{ > + struct task_struct *task; > + ssize_t rc = 0; > + > + task = get_proc_task(file_inode(file)); > + if (!task) > + return -ESRCH; > + > + if (task->flags & PF_MEMALLOC_NOIO) > + rc = simple_read_from_buffer(buf, count, ppos, "noio", 4); > + put_task_struct(task); > + return rc; > +} > + > +static ssize_t memalloc_write(struct file *file, const char __user *buf, > + size_t count, loff_t *ppos) > +{ > + struct task_struct *task; > + char buffer[5]; > + int rc = count; > + > + memset(buffer, 0, sizeof(buffer)); > + if (count != sizeof(buffer) - 1) > + return -EINVAL; > + > + if (copy_from_user(buffer, buf, count)) > + return -EFAULT; > + buffer[count] = '\0'; > + > + task = get_proc_task(file_inode(file)); > + if (!task) > + return -ESRCH; > + > + if (!strcmp(buffer, "noio")) { > + task->flags |= PF_MEMALLOC_NOIO; > + } else { > + rc = -EINVAL; > + } Really? Without any privilege check? So any random user can tap into __GFP_NOIO allocations? NAK. I don't think that it's great idea in general to expose this low-level machinery to userspace. But it's better to get comment from people move familiar with reclaim path. -- Kirill A. Shutemov