Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:Ledest:erlang:23
erlang
2181-Remove-the-file_io_servers-ETS-table.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 2181-Remove-the-file_io_servers-ETS-table.patch of Package erlang
From 8ba186c2d3754a9fbc59de6fb5ce28538c1f2787 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Muska=C5=82a?= <micmus@fb.com> Date: Thu, 19 Jan 2023 11:58:55 +0000 Subject: [PATCH] Remove the file_io_servers ETS table This table was used to store Pids of files opened through the file server, however this data was never used by OTP itself, except for the debugging file:pid2file/1 function. Given the function is deprecated, we can skip the overhead of the central ETS table, and store the name in the file process itself. This makes the pid2file function more expensive, but as a deprecated debugging facility this is acceptable given reduction in overall memory overhead and synchronisation. --- lib/kernel/src/file.erl | 13 +++---------- lib/kernel/src/file_io_server.erl | 12 ++++++++---- lib/kernel/src/file_server.erl | 15 ++------------- lib/kernel/test/file_SUITE.erl | 4 ++-- lib/stdlib/test/error_logger_h_SUITE.erl | 22 +++++++++++----------- 5 files changed, 26 insertions(+), 40 deletions(-) diff --git a/lib/kernel/src/file.erl b/lib/kernel/src/file.erl index 9e5d3fcfbe..e2ed6ef1dc 100644 --- a/lib/kernel/src/file.erl +++ b/lib/kernel/src/file.erl @@ -173,16 +173,9 @@ format_error(ErrorId) -> Pid :: pid(). pid2name(Pid) when is_pid(Pid) -> - case whereis(?FILE_SERVER) of - undefined -> - undefined; - _ -> - case ets:lookup(?FILE_IO_SERVER_TABLE, Pid) of - [{_, Name} | _] -> - {ok, Name}; - _ -> - undefined - end + case file_request(Pid, pid2name) of + {ok, _} = Ok -> Ok; + _ -> undefined end. %%%----------------------------------------------------------------- diff --git a/lib/kernel/src/file_io_server.erl b/lib/kernel/src/file_io_server.erl index 723325bdfb..a85eff1b20 100644 --- a/lib/kernel/src/file_io_server.erl +++ b/lib/kernel/src/file_io_server.erl @@ -26,7 +26,7 @@ -export([count_and_find/3]). --record(state, {handle,owner,mref,buf,read_mode,unic}). +-record(state, {handle,owner,mref,name,buf,read_mode,unic}). -include("file_int.hrl"). @@ -80,8 +80,9 @@ do_start(Spawn, Owner, FileName, ModeList) -> Self ! {Ref, ok}, server_loop( #state{handle = Handle, - owner = Owner, - mref = M, + owner = Owner, + mref = M, + name = FileName, buf = <<>>, read_mode = ReadMode, unic = UnicodeMode}) @@ -322,7 +323,10 @@ file_request({read_handle_info, Opts}, Reply -> {reply,Reply,State} end; -file_request(Unknown, +file_request(pid2name, + #state{name=Name}=State) -> + {reply,{ok,Name},State}; +file_request(Unknown, #state{}=State) -> Reason = {request, Unknown}, {error,{error,Reason},State}. diff --git a/lib/kernel/src/file_server.erl b/lib/kernel/src/file_server.erl index 29eaa23375..12e187902b 100644 --- a/lib/kernel/src/file_server.erl +++ b/lib/kernel/src/file_server.erl @@ -37,8 +37,6 @@ -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). --define(FILE_IO_SERVER_TABLE, file_io_servers). - -define(FILE_SERVER, file_server_2). % Registered name -define(FILE_IO_SERVER, file_io_server). % Module -define(PRIM_FILE, prim_file). % Module @@ -56,7 +54,7 @@ format_error(ErrorId) -> start() -> do_start(start). start_link() -> do_start(start_link). -stop() -> +stop() -> gen_server:call(?FILE_SERVER, stop, infinity). %%%---------------------------------------------------------------------- @@ -77,7 +75,6 @@ stop() -> init([]) -> process_flag(trap_exit, true), - ?FILE_IO_SERVER_TABLE = ets:new(?FILE_IO_SERVER_TABLE, [named_table]), {ok, undefined}. %%---------------------------------------------------------------------- @@ -97,14 +94,7 @@ init([]) -> handle_call({open, Name, ModeList}, {Pid, _Tag} = _From, State) when is_list(ModeList) -> - Child = ?FILE_IO_SERVER:start_link(Pid, Name, ModeList), - case Child of - {ok, P} when is_pid(P) -> - ets:insert(?FILE_IO_SERVER_TABLE, {P, Name}); - _ -> - ok - end, - {reply, Child, State}; + {reply, ?FILE_IO_SERVER:start_link(Pid, Name, ModeList), State}; handle_call({open, _Name, _Mode}, _From, State) -> {reply, {error, einval}, State}; @@ -228,7 +218,6 @@ handle_cast(Msg, State) -> {'noreply', state()}. handle_info({'EXIT', Pid, _Reason}, State) when is_pid(Pid) -> - ets:delete(?FILE_IO_SERVER_TABLE, Pid), {noreply, State}; handle_info(Info, State) -> diff --git a/lib/kernel/test/file_SUITE.erl b/lib/kernel/test/file_SUITE.erl index b791a577f0..aeee1ee8ac 100644 --- a/lib/kernel/test/file_SUITE.erl +++ b/lib/kernel/test/file_SUITE.erl @@ -3451,9 +3451,9 @@ pid2name(Config) when is_list(Config) -> %% {ok, Pid} = file:open(Name1, [write]), {ok, Name2} = file:pid2name(Pid), - undefined = file:pid2name(self()), + Dead = spawn(fun() -> ok end), + undefined = file:pid2name(Dead), ok = file:close(Pid), - ct:sleep(1000), false = is_process_alive(Pid), undefined = file:pid2name(Pid), ok. diff --git a/lib/stdlib/test/error_logger_h_SUITE.erl b/lib/stdlib/test/error_logger_h_SUITE.erl index d1f375459b..0fde51b146 100644 --- a/lib/stdlib/test/error_logger_h_SUITE.erl +++ b/lib/stdlib/test/error_logger_h_SUITE.erl @@ -67,17 +67,17 @@ logfile(Config) -> analyse_events(Log, Ev, [AtNode], unlimited), %% Make sure that the file_io_server process has been stopped - [] = lists:filtermap( - fun(X) -> - case {process_info(X, [current_function]), - file:pid2name(X)} of - {[{current_function, {file_io_server, _, _}}], - {ok,P2N = Log}} -> - {true, {X, P2N}}; - _ -> - false - end - end, processes()), + [] = lists:filtermap(fun(X) -> + case process_info(X, [current_function]) of + [{current_function, {file_io_server, _, _}}] -> + case file:pid2name(X) of + {ok, Log} -> {true, {X, Log}}; + _ -> false + end; + _ -> + false + end + end, processes()), test_server:stop_node(Node), -- 2.35.3
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor