Questions tagged [copy-on-write]
The copy-on-write tag has no usage guidance.
208
questions
0
votes
0
answers
8
views
django "copyOnWrite" for default model instances
Suppose I have a django application that provides Exercises. Those exercises have sub-categories and principles they belong to. Each Exercise belongs to one or no user.
Simplyfied, they look like that:...
1
vote
1
answer
119
views
How can we prove that copy on write is applied to strings of more than 15 characters in Swift?
I wrote the following code in Xcode to try and prove copy on write in Swift:
func print(address o: UnsafeRawPointer) {
print(o)
}
func longStringMemoryTest() {
var longStr1 = "...
0
votes
0
answers
21
views
Find pages that are written in a process after a fork()
I have a fork-based server. After the fork, the server basically just moves data from one socket to another: I expect it to write only to one memory buffer. With Linux' copy-on-write system, I ...
-2
votes
1
answer
55
views
File copy-on-write in Java?
I'm using brtfs, and I'd like my Java program to copy a set of large files copy-on-write.
In other words, what's the equivalent of cp --reflink=auto in some library that hopefully exists and somebody ...
1
vote
2
answers
65
views
Can I change the encoding of a frozen String without copying it?
Can a String and its duplicate share the same underlying memory? Is there copy-on-write in Ruby?
I have a large, frozen String and I want to change its encoding. But I don't want to copy the whole ...
0
votes
1
answer
134
views
Copy-on-write for large data in Python's ProcessPoolExecutor
I want to leverage multiple cores for an expensive computation without copying the large data to all forked processes.
In more detail: The large data is a large (networkx) graph plus certain edges ...
0
votes
1
answer
89
views
Is a call to free() in the forked process causing a copy-on-write? [duplicate]
From man fork(2):
Under Linux, fork() is implemented using copy-on-write pages, so
the only penalty that it incurs is the time and memory required
to duplicate the parent's page tables, and ...
1
vote
1
answer
71
views
Mutating a Julia dictionary through aliases
Let's say I have a dictionary like so:
my_object = Dict{Symbol, Any}(
:foo => Dict{Symbol, Any}(
:foo_items => ["item_a", "item_b", "item_c"],
:...
0
votes
0
answers
133
views
linux process injection, what happen to the shared object file and why the whole memory mapping of the process after the injection changed?
I am trying to improve in Linux process injection and I have some things that i not fully understand.
the injection method that I am using is the basic ptrace injection in current rip value. the flow ...
1
vote
1
answer
104
views
PHP Copy on Write in Arrays vs Objects [duplicate]
I have a question about the copy one write optimization in PHP that I believe is distinct from this and this question marked as a duplicate. I also do not feel the question is addressed here, either ...
6
votes
1
answer
265
views
What is a "container detachement" in the C++11 ranged based loop over QList? Is it a performance only problem?
This question contains some proposals for working around the problem, I would like to understand more in depth that exactly the problem is:
QList<QString> q;
for (QString &x: q) { .. }
Is ...
1
vote
1
answer
362
views
Copy on Write - COW - what happened after the page is modified
I'm learning the copy-on-write technique. I can understand that parent and child process share the same address space. When the parent or child want to modify the page, so that page will be copied to ...
1
vote
0
answers
348
views
xv6 lazy page allocation
While implementing lazy page allocation in xv6, I noticed while tracing back through gdb that the copyout function needs to be changed in order to make sure it is not writing to a page table entry ...
2
votes
2
answers
460
views
Using copy-on-write in multithreading environment in C++
In my Qt C++ application, I have two main threads: the GUI thread and the render thread. The GUI thread manages a list of DataObject structs that can be created and edited, while the render thread ...
2
votes
2
answers
327
views
Copy-on-write style memory reuse for kubernetes pods? To make pod spawn faster and more memory efficient
Can Kubernetes pods share significant amount of memory?
Does copy-on-write style forking exist for pods?
The purpose is to make pods spawn faster and use less memory.
Our scenario is that we have a ...
2
votes
2
answers
111
views
How to find out the memory area of an "optional" in swift?
I am studying CoW.
I understand that under the hood of an array and dictionary, the CoW works.
To check this, I looked at the memory area through the print.
var array1 = [1,2,3]
array1....
0
votes
0
answers
278
views
Does page-fault effect performance much, by forking child process?
I have a busy process which occupies 30% CPU and 1G memory usage, at Linux.
The process makes a snapshot every hour, by calling fork() to create a child process which writes all data to a file. It ...
1
vote
1
answer
220
views
Is COW the same as Demand paging?
I was reading:
https://en.wikipedia.org/wiki/Demand_paging
https://en.wikipedia.org/wiki/Copy-on-write
While I totally understand what COW is, I don't get anything regarding Demand paging, how it's ...
0
votes
0
answers
62
views
Can overwriting 0 still keep copy-on-write?
In a copy on write system, reading does not increase memory, while writing data brings in new pages. And OS also has zero pages, mmap memory addresses would have 0 provided by zero page, and reading 0 ...
0
votes
1
answer
209
views
Cannot find 'isUniquelyReferencedNonObjC' in scope
import Foundation
final class Ref<T> {
var val : T
init(_ v : T) {val = v}
}
struct Box<T> {
var ref : Ref<T>
init(_ x : T) { ref = Ref(x) }
var value: T {
...
0
votes
0
answers
112
views
Windows write-fault exception generated by copy-on-write memory page
I have a Windows application that is working fine on most computers, but on a VM running on an Intel Xeon Gold 6254 processor, I get a write fault exception (0xC000001D) the first time that code ...
-2
votes
1
answer
52
views
Does php's copy on write work with arrays? [duplicate]
Does php's copy on write work with arrays? Also if you could suggest a way to debug when a copy on write is happening that would be appreciated
0
votes
0
answers
226
views
Swift, When assigning the same value type instance to two variables, do only variables corresponding to array types have the same memory address?
I read in Swift value types use copy on write to optimization in OptimizationTips docs
All standard library containers in Swift are value types that use COW (copy-on-write) to perform copies instead ...
2
votes
1
answer
114
views
Copy-on-write for stacks
How to implement copy-on-write technique for stack management in postfix calculations of big numbers?
I want to optimize my system regarding operations like:
duplicate top of stack
swap the two top ...
1
vote
0
answers
90
views
Does QNX support copy-on-write for child process?
As we know on Linux, after the parent process creates a child process by using fork, the child process will have the same memory map as the parent process for the data segment.
When the child process ...
0
votes
1
answer
50
views
How to create copy-write protected pages in a module?
I am trying to make different pages protected and not protected, for example there are 10 pages in my module and I just want to make 5 pages protected (copy-on-write), other won't. How can I do that?
...
3
votes
3
answers
329
views
Copy-on-Write and varargin in MATLAB
MATLAB documentation has the section Avoid Unnecessary Copies of Data in which the following statement can be found:
Copy-on-Write
If a function does not modify an input argument, MATLAB does not ...
2
votes
2
answers
376
views
Swift forEach with assignment inside the block
Let's say I have this
var array = [1,2,3]
array.forEach {
array.append(17)
print($0)
}
It will not loop forever, instead it will print 1, 2 and 3 and afterwards the array has 6 elements: [1,...
2
votes
1
answer
1k
views
Copy file in Python with copy-on-write (COW)
My filesystem (FS) (ZFS specifically) supports copy-on-write (COW), i.e. a copy (if done right) is a very cheap constant operation, and does not actually copy the underlying content. The content is ...
0
votes
0
answers
142
views
Hands-on example of fork's copy-on-write in action
In Linux the system call fork is said to use copy-on-write (COW) mechanism thus avoiding to actually duplicate memory if it's not really needed.
However, I've never seen an actual clear evidence of ...
0
votes
0
answers
166
views
CRIU - checkpointing a TCP socket without stopping it (COW ?)
I'm working on a failover mechanism for TCP connections. If a host breaks down (hardware failure), I'd like to be able to take up the connection on another machine. I want to stream periodically the ...
1
vote
2
answers
435
views
Understanding snapshots in CopyOnWriteArrayList
I have few issues in understanding this concept. Please correct me where I am wrong.
Basically, iteration makes a snapshot (copy) of original array, thus threads that modify collection won't affect ...
2
votes
1
answer
327
views
Is Swift's copy-on-write thread-safe?
Making an array or dictionary a value type by definition, but then actually copying it only when one reference to it tries to modify it is a lovely idea, but it makes me wary in a multi-queued/...
0
votes
1
answer
413
views
Anomaly in CoW (Copy on Write) of Swift Array with Reference type items
My understanding:
Arrays in Swift are value types. Arrays and other collections in Swift has CoW (Copy on Write) mechanism so when an array is passed as an argument to a function or simply assigned ...
2
votes
0
answers
460
views
Memory available (free) plummets and CPU spikes when shutting down uwsgi/gunicorn with process workers
Gist
When I start use copy-on-write to start up a bunch of wsgi workers, they freak out and use a ton of CPU and memory whenever I need to restart the main process. This causes OOM errors and I'd ...
3
votes
0
answers
191
views
Does a value type returned from a function trigger a copy-on-write when modified?
Simple question, but I'm not sure how to test. Does a value type returned from a function always trigger a copy-on-write when it's modified, or are you modifying the exact same instance that was ...
2
votes
1
answer
236
views
If I force unwrap a struct instance, does Swift copy it?
If I force unwrap an optional instance of a struct, does Swift make a copy of it?
For example, in the following code, where Point is a struct, does Swift copy (internally) point when I unwrap it?
...
3
votes
1
answer
1k
views
How does fork() process mark parent's PTE's as read only?
I've searched through a lot of resources, but found nothing concrete on the matter:
I know that with some linux systems, a fork() syscall works with copy-on-write; that is, the parent and the child ...
8
votes
1
answer
1k
views
macOS with APFS: Copy-On-Write in Terminal
I am writing some little script that assembles backup data into one directory. The directory content will then be uploaded to a cloud service and after that we can remove it. I was wondering how one ...
1
vote
1
answer
107
views
Child-runs-first semantics in old linux kernels
I was reading Linux Kernel development and trying to understand process address space semantics in case of fork(). While I'm reading in context of Kernel v2.6, and in newer versions, any of child or ...
0
votes
1
answer
57
views
Why calling a mutating method directly on ArraySlice doesn't trigger the copy-on-write?
Why calling a mutating method directly on ArraySlice doesn't trigger the copy-on-write? The only difference is assigning the slice to a variable, right?
My example codes:
var numbers = [15, 40, 10, ...
5
votes
1
answer
844
views
How to use SmallVec with Cow
I want to use SmallVec with Cow. I tried this:
use smallvec::SmallVec;
use std::borrow::Cow;
fn main() {
let s = "hello world".to_owned();
let mut s = Cow::Borrowed(s.as_bytes());
...
1
vote
1
answer
465
views
Do node.js forked processes share any memory via copy-on-write?
In (some?) Unix systems when you fork a process the new process will share memory with its predecessor. The memory will be shared as long as it's unchaged. This is called cow, copy-on-write.
I wonder ...
4
votes
1
answer
762
views
Custom Index for Linked List in Swift
Custom Index Type for Linked List
Swift 5.0, Xcode 10.3
I recently implemented a doubly linked list type in Swift. When I set out to make it, my goal was to give users most of the same ease of use ...
2
votes
1
answer
1k
views
A Hashmap supporting String and &str
How do I define a HashMap supporting both String and &str in its key and content? I tried the following:
fn mapping<T: Into<String>>() -> HashMap<T, T> {
let mut map: ...
3
votes
1
answer
919
views
How to prevent changes to the underlying file after mmap()-ing a file from being visible to my program?
According to mmap() manpage:
MAP_PRIVATE
Create a private copy-on-write mapping. Updates to the mapping are not visible to other processes mapping the same file, and are not carried through ...
3
votes
1
answer
198
views
Unexpected behavior involving const_cast
I came up with the following example, which exposes some unexpected behavior.
I would expect that after push_back, whatever is in the vector is there.
It looks like the compiler somehow decided to re-...
0
votes
0
answers
368
views
How to prevent page faults after child exits?
A nice way of creating a snapshot of a process is to use fork() to create a child process. The memory of the child process will be a copy of the parent process.
Instead of eagerly copying all the ...
5
votes
1
answer
300
views
Kernel copying CoW pages after child process exit
In Linux, whenever a process is forked, the memory mappings of the parent process are cloned into the child process. In reality, for performance reasons, the pages are set to be copy-on-write -- ...
-1
votes
1
answer
154
views
Do we have to implement copy on write behavior for our custom types?
In Swift, collections are implicitly implemented with copy on write behavior; However, we don't get it for free in our custom types.
My main question is:
Regardless of how to achieve it, is it a ...