Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp103019ybe; Tue, 10 Sep 2019 15:15:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqxdWrq+gw4tKhP9dcTaxi39Ls1Wh6Mve7tngYlE0spAcUV/o0m0DXNcZpeuwPHM2A/YGYWX X-Received: by 2002:a17:906:4e15:: with SMTP id z21mr26962836eju.299.1568153746313; Tue, 10 Sep 2019 15:15:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568153746; cv=none; d=google.com; s=arc-20160816; b=MHgGk0eWhsIv/YakB36kE+GrTvJp+LOkpc/sYJ7u1WNxzFz3JZ4dz2H7g7/57pmCfm FDZmwENN0YFwIHz0BrRoJBGuLtUUsQhFy/0xdIRPFasRyiH7FPNiFtV00aq6aMMf1brM PUstvwLCHVxSpCropi427RJ5+yTFJBg5vnXVmafkC6qcry5eJqb4M6l5oAAxlHr9z3gF R+7GxtZO9Sc3nHNbrClXVMsoXDsQtsQeLrtxjLs1JipBsuc1WXJj7V0LxRPN3s+yuvzq bBT/kRzEvMDf5LXDzNW1SSeLwVljkqSot3fkVCor9l8GYLLrb7XfBvig1paIxiAa0aio KAnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:cc:references:to:subject; bh=CqGiuJaiVyg73w6ULD/FW/hkbG/p8eMqCkmlTSVDQY4=; b=HM1WuI9mZVkS8PcJiAbg0LUIzKEguXmw5igZtp1XDc6nMdk/pKgYzpAusslRssBPXS JK+eGalLyHeijQ6UHPBQ1jw/gqATIMfXr/dHWFew+tqTgocpgSlg5XFh6YI0rl6O5lb3 4/p3UUFl0QHNlmB0yn/kBDh5gS+X+vpf88lqGG4YQBGelC/NkcvTqGpOmoQaDRntFo8Z 6JvEZZkuuDdhZIMZ0uH1gibxhXVztRqfJYXF9eFIqgrxzlQJc9RdYwgTMWjiXO+DLuiU sp9jio1mAZPe5FjG8SZTS2JQuRYN9GL+wvufUHS/imRHXDB/SflPbapFgdzKZABSAcdC SmZQ== ARC-Authentication-Results: i=1; mx.google.com; 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 t6si10127553ejr.238.2019.09.10.15.15.20; Tue, 10 Sep 2019 15:15:46 -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; 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 S1726391AbfIJWM1 (ORCPT + 99 others); Tue, 10 Sep 2019 18:12:27 -0400 Received: from www262.sakura.ne.jp ([202.181.97.72]:53419 "EHLO www262.sakura.ne.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725832AbfIJWM1 (ORCPT ); Tue, 10 Sep 2019 18:12:27 -0400 Received: from fsav405.sakura.ne.jp (fsav405.sakura.ne.jp [133.242.250.104]) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTP id x8AMC70E004224; Wed, 11 Sep 2019 07:12:07 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) Received: from www262.sakura.ne.jp (202.181.97.72) by fsav405.sakura.ne.jp (F-Secure/fsigk_smtp/530/fsav405.sakura.ne.jp); Wed, 11 Sep 2019 07:12:07 +0900 (JST) X-Virus-Status: clean(F-Secure/fsigk_smtp/530/fsav405.sakura.ne.jp) Received: from [192.168.1.8] (softbank126227201116.bbtec.net [126.227.201.116]) (authenticated bits=0) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTPSA id x8AMC7JR004220 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NO); Wed, 11 Sep 2019 07:12:07 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) Subject: Re: [RFC PATCH] Add proc interface to set PF_MEMALLOC flags To: Mike Christie References: <20190909162804.5694-1-mchristi@redhat.com> <5D76995B.1010507@redhat.com> 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, Linux-MM From: Tetsuo Handa Message-ID: Date: Wed, 11 Sep 2019 07:12:06 +0900 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: <5D76995B.1010507@redhat.com> Content-Type: text/plain; charset=windows-1252 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2019/09/10 3:26, Mike Christie wrote: > Forgot to cc linux-mm. > > On 09/09/2019 11:28 AM, 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. Interesting patch. But can't we instead globally mask __GFP_NOFS / __GFP_NOIO than playing games with per a thread masking (which suffers from inability to propagate current thread's mask to other threads indirectly involved)? >> +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)) copy_from_user() / copy_to_user() might involve memory allocation via page fault which has to be done under the mask? Moreover, since just open()ing this file can involve memory allocation, do we forbid open("/proc/thread-self/memalloc") ? >> + 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; >> + } >> + >> + put_task_struct(task); >> + return rc; >> +}