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 X-Spam-Level: X-Spam-Status: No, score=-9.9 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1,USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 51F7AC33CB6 for ; Fri, 17 Jan 2020 09:44:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 27FC820730 for ; Fri, 17 Jan 2020 09:44:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="flAhPTGx" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729117AbgAQJoC (ORCPT ); Fri, 17 Jan 2020 04:44:02 -0500 Received: from mail-pj1-f52.google.com ([209.85.216.52]:32984 "EHLO mail-pj1-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729019AbgAQJoB (ORCPT ); Fri, 17 Jan 2020 04:44:01 -0500 Received: by mail-pj1-f52.google.com with SMTP id u63so4076923pjb.0 for ; Fri, 17 Jan 2020 01:44:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=00G05jNcrM2B7qg+tGmrQSVLLyzjItlORoc+42XWNYc=; b=flAhPTGxlrlifEOZ+Tn9hOXazKmSkeBxFMkQr7zEaZUkHgvdnuNsmY0fYyogJXEd/b k+WQoNlGHUsVjpAWDRB/Ru69KzFJjaHKiJ0LBpYlqMllOy9ImLsOG8RLWkGG8jl5NTKw tfuEheB6PhYV7Kd+eLr1zs1HDMQ1hkFhozggktUGVuvMWLx0IAFD9vtVZ3alEY01ztXH CUCjNUHUIehXaqZCk61UUImcuiv9FODEFzHCcetLk7bbyVkZikDBKRzYgGjP4iNN0YTO pcDX1TzP+wd16+CA+zSn2nIEByurgz6daAUfY5R660xi6M73yTwnSFDp1eUhSaHztJ/Z ejbg== 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:in-reply-to:message-id :references:user-agent:mime-version; bh=00G05jNcrM2B7qg+tGmrQSVLLyzjItlORoc+42XWNYc=; b=QCNSqPOm4Z83NusyN5OnkHH69ntYn5H/r8f+pHRjPwAQOKbjLPzfIiRVVjUBTMKXR6 hJ2EQltjIwAMa6rU4E+KQBLjd6oSgZMW4H+4+61fNI+pukT7fe3ZLP1pMZEpBcVn0XP7 khm2mMaIuJkr8WAzKfZA0ximuIucIaFwx4/pzEEWKipqimpr9LGQEJP1vauRAJOs+Jt2 LmID8MkDHKPZQdMacHi6hnZ7A5Et6AfXCJv9PY4wSQH6UV7EMOfudxIN1Aupc6d8i/PM 46cCY0FYSYAKc1iuurlW5S+h9zgpbUCH+k4EsBCkHLV6NZrh2qReaVYIR5CQ1HCyem2M WpTg== X-Gm-Message-State: APjAAAWOtISfYNoYPshcGgcBQVEep+sCuvx9/X1vMxzdatABjLkh/Co6 /hn7ywMceIC3H2vk5ggwGtttGBveukk= X-Google-Smtp-Source: APXvYqw8Dp4mZAayb4IID1REqC1qp5S0dGgoKB/YWhMp7YhOVOoG6Gu5U+T5/Nnkhnoe4g/ylicm0Q== X-Received: by 2002:a17:902:321:: with SMTP id 30mr38684650pld.130.1579254240671; Fri, 17 Jan 2020 01:44:00 -0800 (PST) Received: from [2620:15c:17:3:3a5:23a7:5e32:4598] ([2620:15c:17:3:3a5:23a7:5e32:4598]) by smtp.gmail.com with ESMTPSA id x132sm28646025pfc.148.2020.01.17.01.43.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jan 2020 01:44:00 -0800 (PST) Date: Fri, 17 Jan 2020 01:43:59 -0800 (PST) From: David Rientjes X-X-Sender: rientjes@chino.kir.corp.google.com To: Vlastimil Babka cc: Andrew Morton , Mel Gorman , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [patch] mm, thp: fix defrag setting if newline is not used In-Reply-To: <025511aa-4721-2edb-d658-78d6368a9101@suse.cz> Message-ID: References: <20200116191609.3972fd5301cf364a27381923@linux-foundation.org> <025511aa-4721-2edb-d658-78d6368a9101@suse.cz> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 17 Jan 2020, Vlastimil Babka wrote: > >> If thp defrag setting "defer" is used and a newline is *not* used when > >> writing to the sysfs file, this is interpreted as the "defer+madvise" > >> option. > >> > >> This is because we do prefix matching and if five characters are written > >> without a newline, the current code ends up comparing to the first five > >> bytes of the "defer+madvise" option and using that instead. > >> > >> Find the length of what the user is writing and use that to guide our > >> decision on which string comparison to do. > > > > Gee, why is this code so complicated? Can't we just do > > > > if (sysfs_streq(buf, "always")) { > > ... > > } else if sysfs_streq(buf, "defer+madvise")) { > > ... > > } > > ... > > Yeah, if we knew this existed :) > > We would lose the prefix matching but hopefully nobody will complain. > I tested Vlastimil's patch and it works as intended so I was about to modify the changelog and send his patch and ask for a sign-off line because I think I agree the *partial* prefix matching has ~0.1% chance of breaking userspace and that 0.1% chance outweighs my desire to make the code consistent for all options. But if userspace were broken by this, then at least it was already broken for "defer" depending on newline vs no newline. (What we do know is that nobody has used "defer" for the past couple years without a newline :). If nobody objects, I'll test and send Andrew's version with the changelog because I think we all agree the risk of breakage here is very minimal and actually fixes the case for defer. 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 X-Spam-Level: X-Spam-Status: No, score=-9.9 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1,USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1A35FC33CB1 for ; Fri, 17 Jan 2020 09:44:04 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CD5C02087E for ; Fri, 17 Jan 2020 09:44:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="flAhPTGx" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CD5C02087E Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 9B7A86B0348; Fri, 17 Jan 2020 04:44:02 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9688D6B0349; Fri, 17 Jan 2020 04:44:02 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8573A6B034A; Fri, 17 Jan 2020 04:44:02 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0211.hostedemail.com [216.40.44.211]) by kanga.kvack.org (Postfix) with ESMTP id 712AD6B0348 for ; Fri, 17 Jan 2020 04:44:02 -0500 (EST) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with SMTP id 44859A8DB for ; Fri, 17 Jan 2020 09:44:02 +0000 (UTC) X-FDA: 76386639924.19.grain68_2335460ad9220 X-HE-Tag: grain68_2335460ad9220 X-Filterd-Recvd-Size: 4850 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) by imf44.hostedemail.com (Postfix) with ESMTP for ; Fri, 17 Jan 2020 09:44:01 +0000 (UTC) Received: by mail-pl1-f172.google.com with SMTP id c9so4354456plo.1 for ; Fri, 17 Jan 2020 01:44:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=00G05jNcrM2B7qg+tGmrQSVLLyzjItlORoc+42XWNYc=; b=flAhPTGxlrlifEOZ+Tn9hOXazKmSkeBxFMkQr7zEaZUkHgvdnuNsmY0fYyogJXEd/b k+WQoNlGHUsVjpAWDRB/Ru69KzFJjaHKiJ0LBpYlqMllOy9ImLsOG8RLWkGG8jl5NTKw tfuEheB6PhYV7Kd+eLr1zs1HDMQ1hkFhozggktUGVuvMWLx0IAFD9vtVZ3alEY01ztXH CUCjNUHUIehXaqZCk61UUImcuiv9FODEFzHCcetLk7bbyVkZikDBKRzYgGjP4iNN0YTO pcDX1TzP+wd16+CA+zSn2nIEByurgz6daAUfY5R660xi6M73yTwnSFDp1eUhSaHztJ/Z ejbg== 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:in-reply-to:message-id :references:user-agent:mime-version; bh=00G05jNcrM2B7qg+tGmrQSVLLyzjItlORoc+42XWNYc=; b=paX540qtLNMBdZq2zclpDtRx39GU2Xlgy9nNAXrFLRD1SvTKn7qoogAXDbYPje/zY5 YAJFiGbWMBe+RjEIEKY2T23jUm/YWbLo/CsVnzbn7EGd2v+R9sH7gc9fUU5goiDFxtlx Ld2S7GF8IovL4iFr9gvANbrDlqdhv/iJEcp2H52sUQPgKe9VS0W3jg9cVrn6OgFWgpY6 MhqWMy81nE8KMjhDqnaMp7lgSiP63bzqCHzhQ/ZJNUiw4+OlZ8KR/rVzqg0Qp5m3x7pH 3SGrfqPUImiTvZzdJInakgtX7wQvj9j+DfDU/UzkEAC5GHGkECoy/AZClm4T7iHqYMLz +gUg== X-Gm-Message-State: APjAAAVXO071CGdd4N/dAYWRWIo1oSvGZ4BbDgMuKGBzBXSN1Dzgddfn u3UMyVjHUoBV0yrbvRYdYHHJ6g== X-Google-Smtp-Source: APXvYqw8Dp4mZAayb4IID1REqC1qp5S0dGgoKB/YWhMp7YhOVOoG6Gu5U+T5/Nnkhnoe4g/ylicm0Q== X-Received: by 2002:a17:902:321:: with SMTP id 30mr38684650pld.130.1579254240671; Fri, 17 Jan 2020 01:44:00 -0800 (PST) Received: from [2620:15c:17:3:3a5:23a7:5e32:4598] ([2620:15c:17:3:3a5:23a7:5e32:4598]) by smtp.gmail.com with ESMTPSA id x132sm28646025pfc.148.2020.01.17.01.43.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jan 2020 01:44:00 -0800 (PST) Date: Fri, 17 Jan 2020 01:43:59 -0800 (PST) From: David Rientjes X-X-Sender: rientjes@chino.kir.corp.google.com To: Vlastimil Babka cc: Andrew Morton , Mel Gorman , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [patch] mm, thp: fix defrag setting if newline is not used In-Reply-To: <025511aa-4721-2edb-d658-78d6368a9101@suse.cz> Message-ID: References: <20200116191609.3972fd5301cf364a27381923@linux-foundation.org> <025511aa-4721-2edb-d658-78d6368a9101@suse.cz> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII 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 Fri, 17 Jan 2020, Vlastimil Babka wrote: > >> If thp defrag setting "defer" is used and a newline is *not* used when > >> writing to the sysfs file, this is interpreted as the "defer+madvise" > >> option. > >> > >> This is because we do prefix matching and if five characters are written > >> without a newline, the current code ends up comparing to the first five > >> bytes of the "defer+madvise" option and using that instead. > >> > >> Find the length of what the user is writing and use that to guide our > >> decision on which string comparison to do. > > > > Gee, why is this code so complicated? Can't we just do > > > > if (sysfs_streq(buf, "always")) { > > ... > > } else if sysfs_streq(buf, "defer+madvise")) { > > ... > > } > > ... > > Yeah, if we knew this existed :) > > We would lose the prefix matching but hopefully nobody will complain. > I tested Vlastimil's patch and it works as intended so I was about to modify the changelog and send his patch and ask for a sign-off line because I think I agree the *partial* prefix matching has ~0.1% chance of breaking userspace and that 0.1% chance outweighs my desire to make the code consistent for all options. But if userspace were broken by this, then at least it was already broken for "defer" depending on newline vs no newline. (What we do know is that nobody has used "defer" for the past couple years without a newline :). If nobody objects, I'll test and send Andrew's version with the changelog because I think we all agree the risk of breakage here is very minimal and actually fixes the case for defer.