MC504 Sistemas Operacionais
Prof. Dr. Eng. Isaías Bittencourt Felzmann
isaias@ic.unicamp.br
Campinas, 2s/2026
Gerenciamento de Memória
1/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Copyright Note
The following set of slides are copyright Silberschatz, Galvin and Gagne, 2018. Modifications were made for their use in conjunction with MC504. The original material is available at os-book.com .
Os direitos autorais do conjunto de slides a seguir pertencem a Silberschatz, Galvin and Gagne, 2018. Foram feitas modificações para seu uso em MC504. O material original está disponível em os-book.com .
Este material foi elaborado com apoio de ferramentas de IA generativa como recurso auxiliar. O conteúdo foi revisado, validado e é de responsabilidade do docente.
2/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Fundamentos
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
3/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Proteção
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
4/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Proteção de Endereços por Hardware
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
5/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Vinculação de Endereços
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
6/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Vinculação de Instruções e Dados à Memória
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
7/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Etapas de Processamento de um Programa de Usuário
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
8/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Espaço de Endereçamento Lógico vs. Físico
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
9/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Unidade de Gerenciamento de Memória (MMU)
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
10/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Unidade de Gerenciamento de Memória (Cont.)
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
11/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Unidade de Gerenciamento de Memória (Cont.)
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
12/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Alocação Contígua
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
13/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Alocação Contígua (Cont.)
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
14/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Suporte de Hardware aos Registradores de Relocação e Limite
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
15/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
�Partição Variável
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
16/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Problema de Alocação Dinâmica de Memória
Como atender a uma requisição de tamanho n a partir de uma lista de lacunas livres?
First-fit e best-fit são melhores que worst-fit em termos de velocidade e de utilização da memória
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
17/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Fragmentação
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
18/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Fragmentação (Cont.)
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
19/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Paginação
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
20/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Esquema de Tradução de Endereços
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
21/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Hardware de Paginação
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
22/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Modelo de Paginação da Memória Lógica e Física
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
23/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Exemplo de Paginação
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
24/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Paginação -- Cálculo da fragmentação interna
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
25/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Frames Livres
Antes da alocação
Depois da alocação
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
26/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Implementação da Tabela de Páginas
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
27/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Translation Look-Aside Buffer
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
28/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Hardware do TLB
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
29/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Hardware de Paginação com TLB
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
30/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Proteção de Memória
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
31/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Bit Válido (v) ou Inválido (i) em uma Tabela de Páginas
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
32/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Carregamento Dinâmico
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
33/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Ligação Dinâmica
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
34/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Páginas Compartilhadas
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
35/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Exemplo de Páginas Compartilhadas
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
36/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Swapping
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
37/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Swapping (Cont.)
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
38/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Visão Esquemática do Swapping
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
39/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Tempo de Troca de Contexto incluindo Swapping
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
40/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Tempo de Troca de Contexto e Swapping (Cont.)
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
41/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Swapping em Sistemas Móveis
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
42/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Swapping com Paginação
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
43/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Fundamentos
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
44/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Memória virtual
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
45/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Memória virtual (Cont.)
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
46/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Memória Virtual Maior que a Memória Física
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
47/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Espaço de Endereçamento Virtual
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
48/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Biblioteca Compartilhada com Memória Virtual
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
49/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Paginação sob Demanda
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
50/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Paginação sob Demanda
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
51/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Conceitos Básicos
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
52/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Bit Válido-Inválido
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
53/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Tabela de Páginas Quando Algumas Páginas Não Estão�na Memória Principal
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
54/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Etapas no Tratamento de um Page Fault
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
55/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Etapas no Tratamento de um Page Fault (Cont.)
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
56/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Aspectos da Paginação sob Demanda
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
57/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Lista de Frames Livres
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
58/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
�Etapas da Paginação sob Demanda – Pior Caso
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
59/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Etapas da Paginação sob Demanda (Cont.)
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
60/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Desempenho da Paginação sob Demanda
EAT = (1 – p) x acesso à memória
+ p (overhead do page fault
+ swap out da página
+ swap in da página )
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
61/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Exemplo de Paginação sob Demanda
= (1 – p x 200 + p x 8.000.000
= 200 + p x 7.999.800
EAT = 8,2 microssegundos.
Isso representa uma desaceleração por um fator de 40!!
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
62/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Otimizações da Paginação sob Demanda
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
63/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Copy-on-Write
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
64/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Antes de o Processo 1 Modificar a Página C
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
65/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Depois de o Processo 1 Modificar a Página C
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
66/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
O Que Acontece Se Não Houver Frame Livre?
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
67/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Substituição de Páginas
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
68/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Necessidade de Substituição de Páginas
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
69/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Substituição de Páginas Básica
Observe que agora há potencialmente 2 transferências de página por page fault – aumentando o EAT
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
70/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Substituição de Páginas
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
71/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Algoritmos de Substituição de Páginas e de Frames
7,0,1,2,0,3,0,4,2,3,0,3,2,1,2,0,1,7,0,1
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
72/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Algoritmo First-In-First-Out (FIFO)
�
15 page faults
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
73/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
FIFO Ilustrando a Anomalia de Belady
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
74/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Algoritmo Ótimo
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
75/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Algoritmo Least Recently Used (LRU)
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
76/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Algoritmo LRU (Cont.)
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
77/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Algoritmo LRU (Cont.)
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
78/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Algoritmos de Aproximação do LRU
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
79/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Algoritmos de Aproximação do LRU (cont.)
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
80/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
�Algoritmo da Segunda Chance
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
81/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Algoritmo da Segunda Chance Aprimorado
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
82/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Algoritmos de Contagem
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
83/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Algoritmos de Buffering de Páginas
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
84/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Aplicações e Substituição de Páginas
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
85/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Alocação de Frames
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
86/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Alocação Fixa
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
87/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Alocação Global vs. Local
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
88/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Thrashing
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
89/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Thrashing (Cont.)
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
90/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Paginação sob Demanda e Thrashing
� Modelo de localidade
� Σ tamanho da localidade > tamanho total da memória
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
91/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Localidade em um Padrão de Referências à Memória
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
92/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Frequência de Page Faults
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
93/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Pré-paginação
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
94/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Tamanho de Página
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
95/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Alcance do TLB
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
96/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Estrutura do Programa
for (j = 0; j <128; j++)� for (i = 0; i < 128; i++)� data[i,j] = 0;�
128 x 128 = 16.384 page faults �
for (i = 0; i < 128; i++)� for (j = 0; j < 128; j++)� data[i,j] = 0;
�128 page faults
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
97/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Interlock de E/S
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
98/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Windows
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
99/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Bibliografia
Capítulo 3.
Capítulos 9 e 10.
100/100
2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais