Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp8814182imu; Tue, 4 Dec 2018 14:50:36 -0800 (PST) X-Google-Smtp-Source: AFSGD/U+oZWZshYyLaDSPfO6LXJDrttpJawqFKYD5fuIE3xxQG+a0q4XgfXFk+CMn6bGp7PtcTad X-Received: by 2002:a62:2b8b:: with SMTP id r133mr10548591pfr.246.1543963836244; Tue, 04 Dec 2018 14:50:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543963836; cv=none; d=google.com; s=arc-20160816; b=M6/03a/N6wdfNw4hTENYqWwPVmV+7xkGI62wrL50x4TFAiMshVgI1sHjtc5d486Vwm Kg2YXpZkemtHUDiyG1Rfw+YlbXiLilMv8prZ0HEONT/BarfOalNldUzMInX8HVNEuUzX 1n65mQABL3eH7cWttRRiZ/cZy5IfoueR3zVsBAWIzxOSRrSBteOHlY+6d8fNHxWS++2/ XDwuxEFBw5cgNWqZTtZvqH463i10Adbhy9+nksWIRoKJ6forzWw9Gv8aLSqVRwZPwtZo tmnzGwBHYAD35GgWtI3wceTgTEPVzUCCuZ/NCMkybVUsfKRyNM/xWOLfygP/MmhezAFf ZH2w== 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:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=ATqf1JUN2QmiYvbsW7s57k/zMxVIGrODiwvWhe24kGk=; b=VofBKg/rq5VjljbAxB+qTUzStKr1l738YkOjiFqLARSOEmB3pgxuyxPSYHYokV+ywN yv1vvqHpblBZrbScgwSWBWqUV21khst/3Tpd/lL+W0ATw6oKFjzCAB8kkvLbNIVS7erd vh4BZDfDzUlm9BvhReBkAx0uAK57J+UnPJa483l9R1C4HPm95zGGUub3tKbdwy6FS6Jx 1vDSWSJqmjCM2wNtbUtZmNoM37LnR1VJLcbV9/ofCoTcavumxXbtYeITjcHzzXkxyWoj FMyQ4mtVkyFgb/pAQeYmf55/FATAE4ifWbonsCiuzlotKkuZeNZDGuC9a91oP9qj+YI4 Gm8A== 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 j20si16194592pgh.224.2018.12.04.14.50.21; Tue, 04 Dec 2018 14:50:36 -0800 (PST) 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 S1726537AbeLDWte (ORCPT + 99 others); Tue, 4 Dec 2018 17:49:34 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:47300 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725895AbeLDWte (ORCPT ); Tue, 4 Dec 2018 17:49:34 -0500 Received: from akpm3.svl.corp.google.com (unknown [104.133.8.65]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id B54AA8A5; Tue, 4 Dec 2018 22:49:32 +0000 (UTC) Date: Tue, 4 Dec 2018 14:49:31 -0800 From: Andrew Morton To: Josef Bacik Cc: kernel-team@fb.com, hannes@cmpxchg.org, linux-kernel@vger.kernel.org, tj@kernel.org, david@fromorbit.com, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, riel@redhat.com, jack@suse.cz Subject: Re: [PATCH 0/4][V4] drop the mmap_sem when doing IO in the fault path Message-Id: <20181204144931.03566f7e21615e3c2c1b18e8@linux-foundation.org> In-Reply-To: <20181130195812.19536-1-josef@toxicpanda.com> References: <20181130195812.19536-1-josef@toxicpanda.com> X-Mailer: Sylpheed 3.6.0 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 30 Nov 2018 14:58:08 -0500 Josef Bacik wrote: > Now that we have proper isolation in place with cgroups2 we have started going > through and fixing the various priority inversions. Most are all gone now, but > this one is sort of weird since it's not necessarily a priority inversion that > happens within the kernel, but rather because of something userspace does. > > We have giant applications that we want to protect, and parts of these giant > applications do things like watch the system state to determine how healthy the > box is for load balancing and such. This involves running 'ps' or other such > utilities. These utilities will often walk /proc//whatever, and these > files can sometimes need to down_read(&task->mmap_sem). Not usually a big deal, > but we noticed when we are stress testing that sometimes our protected > application has latency spikes trying to get the mmap_sem for tasks that are in > lower priority cgroups. > > This is because any down_write() on a semaphore essentially turns it into a > mutex, so even if we currently have it held for reading, any new readers will > not be allowed on to keep from starving the writer. This is fine, except a > lower priority task could be stuck doing IO because it has been throttled to the > point that its IO is taking much longer than normal. But because a higher > priority group depends on this completing it is now stuck behind lower priority > work. > > In order to avoid this particular priority inversion we want to use the existing > retry mechanism to stop from holding the mmap_sem at all if we are going to do > IO. This already exists in the read case sort of, but needed to be extended for > more than just grabbing the page lock. With io.latency we throttle at > submit_bio() time, so the readahead stuff can block and even page_cache_read can > block, so all these paths need to have the mmap_sem dropped. > > The other big thing is ->page_mkwrite. btrfs is particularly shitty here > because we have to reserve space for the dirty page, which can be a very > expensive operation. We use the same retry method as the read path, and simply > cache the page and verify the page is still setup properly the next pass through > ->page_mkwrite(). Seems reasonable. I have a few minorish changeloggish comments. We're at v4 and no acks have been gathered?